Github Actions Fails with Reading Jtoken from Jsonreader Error

I am trying to follow the How to use GitHub Actions build matrix to deploy artifacts to multiple servers tutorial. I have finished halfway through the tutorial, however, I get the following error when it builds the app.

Error when evaluating 'strategy' for job 'prepare-release-on-servers'. (Line: 53, Col: 17): Error reading JToken from JsonReader. Path '', line 0, position 0.,(Line: 53, Col: 17): Unexpected value ''

I have checked the JSON file for validation and gone through the deployment file countless times.

Here is the deploy-application.yml file.

name: Deploy Application

on:
  push:
    branches:
      - main

jobs:
  create-deployment-artifacts:
    name: Create deployment artifacts
    runs-on: ubuntu-latest
    outputs:
      deployment-matrix: ${{ steps.export-deployment-matrix.outputs.deployment-matrix }}

    steps:
      - uses: actions/checkout@v2
      - name: Compile CSS and Javascript
        run: |
          npm install
          npm run prod

      - name: Configure PHP 8.0
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.0
          extensions: mbstring, ctype, fileinfo, openssl, PDO, bcmath, json, tokenizer, xml
      - name: composer install
        run: |
          composer install --no-dev --no-interaction --prefer-dist
      - name: Create deployment artifact
        env:
          GITHUB_SHA: ${{ github.sha }}
        run: tar -czf "${GITHUB_SHA}".tar.gz --exclude=*.git --exclude=node_modules --exclude=tests *
      - name: Store artifact for distribution
        uses: actions/upload-artifact@v2
        with:
          name: app-build
          path: ${{ github.sha }}.tar.gz
      - name: Export deployment matrix
        id: export-deployment-matrix
        run: |
          JSON="$(cat ./deployment-config.json)"
          JSON="${JSON//'%'/'%25'}"
          JSON="${JSON//$'\n'/'%0A'}"
          JSON="${JSON//$'\r'/'%0D'}"
          echo "::set-output name=deployment-matrix::$(echo $JSON)"
  prepare-release-on-servers:
    name: "${{ matrix.server.name }}: Prepare release"
    runs-on: ubuntu-latest
    needs: create-deployment-artifacts
    strategy:
      matrix:
        server: ${{ fromJson(needs.create-deployment-artifacts.outputs.deployment-matrix) }}
    steps:
      - uses: actions/download-artifact@v2
        with:
          name: app-build

Here is the JSON file.

[{"name":"server-1","ip":"216.656.30.240","username":"root","password":"sdddssafilgwzxcxvgvggfdassa","port":"22","beforeHooks":"","afterHooks": "","path": "/var/www/html" }]

I cannot find the problem here. Any help would be nice. Thanks in advance.

1

2 Answers

Maybe you should follow the instructions of Philo article link

This code is also running deprecated commands(set-output). so you need also not to use them anymore and use the new ones.

  • name: Set output run:

    echo "{name}={value}" >> $GITHUB_OUTPUT
    

I also suffered on this issue several hours & finally got this.

run: |
   delimiter="$(openssl rand -hex 8)"
   JSON="$(cat ./deployment-config.json)"
   echo "deployment_matrix<<${delimiter}" >> "${GITHUB_OUTPUT}"
   echo "$JSON" >> "${GITHUB_OUTPUT}"
   echo "${delimiter}" >> "${GITHUB_OUTPUT}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest