question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New environment file issues with Outputs and fromJson

See original GitHub issue

Describe the bug Getting deprecated “set-output” command warning, so I decided to update the notation to use github environment files, but started getting these errors in both self-hosted and GitHub-hosted servers:

Error when evaluating 'strategy' for job 'Test_Second_Job'. .github/workflows/github-actions-demo.yml (Line: 28, Col: 21): Error parsing fromJson,.github/workflows/github-actions-demo.yml (Line: 28, Col: 21): Error reading JToken from JsonReader. Path '', line 0, position 0.,.github/workflows/github-actions-demo.yml (Line: 28, Col: 21): Unexpected type of value '', expected type: Sequence.

I made changes according to the following link: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

I created a very basic version of the workflow yaml file to try and pinpoint the issue as in the below link, but even that is giving the same errors: https://github.com/TheOnlyWei/github_actions_test/blob/env-filetest/.github/workflows/github-actions-demo.yml https://github.com/TheOnlyWei/github_actions_test/actions/runs/3398602911

name: GitHub Actions Demo
on: 
  pull_request:
    branches:
      - main
  workflow_dispatch:

jobs:
  Test_First_Job:
    runs-on: windows-2019
    steps:
      - name: Convert input to JSON for matrix.
        id: matrix_json_step
        shell: pwsh
        run: |
          $jsonArrayString = "[`"test1:test2:test3`",`"test4:test5:test6`"]"
          echo "JSON_ARRAY=${jsonArrayString}" >> $GITHUB_OUTPUT

    outputs:
      JSON_ARRAY: ${{ steps.matrix_json_step.outputs.JSON_ARRAY }}

  Test_Second_Job:
    runs-on: windows-2019
    needs: Test_First_Job
    strategy:
      fail-fast: false
      matrix:
        JSON_ARRAY: ${{ fromJson(needs.Test_First_Job.outputs.JSON_ARRAY) }}
    steps:
      - name: Print JSON_ARRAY
        shell: pwsh
        run: |
          Write-Host "JSON_ARRAY VALUE IN SECOND JOB: ${{ matrix.JSON_ARRAY }}"

Anyone know how to fix this error? According to official document, the above should work. The above code worked fine with old “set-output” format.

According to fromJson doc, the above should work? https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson

To Reproduce See above.

Expected behavior Expected behavior is that using the new GitHub environment file should produce no errors like the deprecated “set-output” command, but there is an error.

Runner Version and Platform

Version of your runner? 2.298.2

OS of the machine running the runner? OSX/Windows/Linux/… Windows Server 2016 Datacenter

What’s not working?

See above.

Job Log Output

See above.

Runner and Worker’s Diagnostic Logs

Not applicable.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:5
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
NPGiorgicommented, Nov 8, 2022

Same is happening to me, and the issue seems to be specific to fromJson + matrix. My process is:

  • First job creates json, save it as output
  • Second job grabs json from first job output, parses it and prints it (works fine, added for debugging porpuses)
  • Third job uses the json from first job output to build a matrix strategy (get the same error stated above)

Error:

Error when evaluating 'strategy' for job 'build_job_name'. .github/workflows/workflow_name.yaml (Line: 118, Col: 15): Error parsing fromJson,.github/workflows/workflow_name.yaml (Line: 118, Col: 15): Error reading JToken from JsonReader. Path '', line 0, position 0.,.github/workflows/deploy_dev.yaml (Line: 118, Col: 15): Unexpected type of value '', expected type: Mapping.

Also I need to add this was working fine before, and it was broken when I came back to work on Monday. I’ve been trying to fix it since without luck.

0reactions
LinqLovercommented, Jun 9, 2023

For any googlers, I had a similar problem in bash because I used double quotes (") instead of single quotes (') when creating the output. In my case, I could fix the issue by changing

-          echo "my-array<<EOF
+          echo 'my-array<<EOF
           ${{ toJson(fromJson('["Trunk", "6.0"]')) }}
-          EOF" >> $GITHUB_OUTPUT
+          EOF' >> $GITHUB_OUTPUT

https://github.com/hpi-swa-lab/SqueakByExample-english/pull/137/commits/01707f0b56ac9eacc2bb003e6b354174434ceb07

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying to parse JSON output in a Github Action
So for me, I'm running jq command and extracting the value of the authorizationToken from the json text, from inside the file at.json...
Read more >
Expand environment variable from JSON file
When I first ran this, I got an error message starting with jq: error: ENV/0 is not defined at <top-level> . It turns...
Read more >
Use Environment Variable in your next Golang Project
There are multiple ways in golang to use environment variables and files. ... Create a new .env file in the project root directory....
Read more >
GitHub Actions: sets the `CI` environment variable to true
The Actions expression language has a fromJSON(value) method that can take a stingified JSON object and bind it to a property. Combining this ......
Read more >
Json to env. If environmentFolderPath isn't defined, Teams ...
So if you want to use ng serve with a specific environment file (say dev2), you first need to modify the build section...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found