Toolkit: toJson(steps) always empty

Created on 8 Feb 2020  Â·  6Comments  Â·  Source: actions/toolkit

Describe the bug
The documentation on exploring contexts found at "Example printing context information to the log file" says I should be able to add a step that dumps the context of all the steps.

This issue is mentioned in passing in #126. However, the specific solution for that user doesn't actually address the fact that toJson(steps) seems to always be empty, contrary to what the documentation appears to say.

on: push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - id: java-setup-jdk-fx-8
        name: Set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
          java-package: jdk+fx
      - id: build-maven
        name: Build with Maven
        run: mvn -B -U -V -DskipTests compile
        env:
          NEXUS_DEPLOY_PASSWORD: ${{ secrets.NEXUS_DEPLOY_PASSWORD }}
      - name: Dump steps context
        env:
          STEPS_CONTEXT: ${{ toJson(steps) }}
        run: echo "$STEPS_CONTEXT"

However, it is always empty:

2020-02-08T22:10:41.3462849Z ##[group]Run echo "$STEPS_CONTEXT"
2020-02-08T22:10:41.3463099Z echo "$STEPS_CONTEXT"
2020-02-08T22:10:41.3484305Z shell: /usr/bin/bash -e {0}
2020-02-08T22:10:41.3484484Z env:
2020-02-08T22:10:41.3484764Z   JAVA_HOME: /_work/_tool/jdk+fx/8.0.232/x64
2020-02-08T22:10:41.3484945Z   JAVA_HOME_8.0.232_x64: /_work/_tool/jdk+fx/8.0.232/x64
2020-02-08T22:10:41.3485123Z   STEPS_CONTEXT: {}
2020-02-08T22:10:41.3485285Z ##[endgroup]

To Reproduce
Steps to reproduce the behavior: see above.

Expected behavior
A JSON dump of the context of all steps.

question

Most helpful comment

Hey @afwn90cj93201nixr2e1re ,

The steps context is not getting populated in your example because you need to set the id field. This is the field in the step context you can reference it by.

For example you can set your steps to be:

  steps:
      - {name: 'Dump GitHub context', id: 'github_step', env: {GITHUB_CONTEXT: '${{ toJson(github) }}'}, run: 'echo "$GITHUB_CONTEXT"'}
      - {name: 'Dump job context', id: 'job_step', env: {JOB_CONTEXT: '${{ toJson(job) }}'}, run: 'echo "$JOB_CONTEXT"'}
      - {name: 'Check_Arg', id: 'arg_step', shell: bash, run: 'exit 1'}
      - {name: 'Check Arg1', id: 'step', if: always(), run: 'echo ${{toJson(steps.arg_step)}}'}
      - {name: 'Dump steps context', if: always(), env: {STEPS_CONTEXT: '${{ toJson(steps) }}'}, run: 'echo "$STEPS_CONTEXT"'}

And you will see the output

Run echo "$STEPS_CONTEXT"
  echo "$STEPS_CONTEXT"
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
  env:
    STEPS_CONTEXT: {
    "github_step": {
      "outputs": {},
      "outcome": "Success",
      "conclusion": "Success"
    },
    "job_step": {
      "outputs": {},
      "outcome": "Success",
      "conclusion": "Success"
    },
    "arg_step": {
      "outputs": {},
      "outcome": "Failure",
      "conclusion": "Failure"
    },
    "step": {
      "outputs": {},
      "outcome": "Failure",
      "conclusion": "Failure"
    }
  }

Thank you for your feedback regarding the documentation, I'll go ahead and get that updated so we can alleviate this confusion! We should be directly stating that only steps with id:'s will have entries in the step context.

We recently added the conclusion and outcome fields, they were not available when I originally responded, but I hope they prove helpful to you!

All 6 comments

@rbellamy , the steps content only consists of outputs from steps at this moment. if your steps don't have any outputs set, you will get an empty steps context.

Try using the set-output command then echoing the steps contexts
For example:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - id: test
      run: echo "::set-output name=foo::bar"
    - name: Dump steps context
      env:
        STEPS_CONTEXT: ${{ toJson(steps) }}
      run: echo "$STEPS_CONTEXT"

You should see the output

{
  "test": {
    "outputs": {
      "foo": "bar"
    }
  }
}

We document what is in the steps context here: https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context

Em...
изображение
Why we should make any output for getting any output? Why toJson not giving any valid result? It's just empty... How i should know what's going inside without any dumped info? Im not god.
@thboop

Then why we need default options which are should be defined everytime? Why they r described in docs if they rn't exists at all?
Docs are shitty too much, only output's object desribed, then maybe we should remove .conclusion and outcome which are not defined by default at all?

изображение
That's exactly stupid using set-output as temp variable, what about cases when i have more then 100 complicated tasks? I should set 100 outputs? Yep, that's kind.

name: 'Build from comment'
on:
    repository_dispatch:
        types: [Build]

jobs:
        one:
            runs-on: ubuntu-16.04
            steps:
                - {name: 'Dump GitHub context', env: {GITHUB_CONTEXT: '${{ toJson(github) }}'}, run: 'echo "$GITHUB_CONTEXT"'}
                - {name: 'Dump job context', env: {JOB_CONTEXT: '${{ toJson(job) }}'}, run: 'echo "$JOB_CONTEXT"'}
                - {name: 'Dump steps context', env: {STEPS_CONTEXT: '${{ toJson(steps) }}'}, run: 'echo "$STEPS_CONTEXT"'}
                - {name: 'Dump runner context', env: {RUNNER_CONTEXT: '${{ toJson(runner) }}'}, run: 'echo "$RUNNER_CONTEXT"'}
                - {name: 'Check_Arg', shell: bash, run: 'exit 1'}
                - {name: 'Check Arg1', if: always(), run: 'echo ${{toJson(steps.Check_Arg)}}'}
                - {name: 'Check Arg2', if: always(), run: 'echo ${{toJson(job.steps.Check_Arg)}}'}
                - {name: 'Check Arg2', if: always(), run: 'echo ${{steps.Check_Arg.conclusion}}'}
                - {name: 'Check Arg2', if: always(), run: 'echo ${{job.steps.Check_Arg.conclusion}}'}
                - {name: 'Dump strategy context', if: always(), env: {STRATEGY_CONTEXT: '${{ toJson(strategy) }}'}, run: 'echo "$STRATEGY_CONTEXT"'}
                - {name: 'Dump matrix context', if: always(), env: {MATRIX_CONTEXT: '${{ toJson(matrix) }}'}, run: 'echo "$MATRIX_CONTEXT"'}

Hey @afwn90cj93201nixr2e1re ,

The steps context is not getting populated in your example because you need to set the id field. This is the field in the step context you can reference it by.

For example you can set your steps to be:

  steps:
      - {name: 'Dump GitHub context', id: 'github_step', env: {GITHUB_CONTEXT: '${{ toJson(github) }}'}, run: 'echo "$GITHUB_CONTEXT"'}
      - {name: 'Dump job context', id: 'job_step', env: {JOB_CONTEXT: '${{ toJson(job) }}'}, run: 'echo "$JOB_CONTEXT"'}
      - {name: 'Check_Arg', id: 'arg_step', shell: bash, run: 'exit 1'}
      - {name: 'Check Arg1', id: 'step', if: always(), run: 'echo ${{toJson(steps.arg_step)}}'}
      - {name: 'Dump steps context', if: always(), env: {STEPS_CONTEXT: '${{ toJson(steps) }}'}, run: 'echo "$STEPS_CONTEXT"'}

And you will see the output

Run echo "$STEPS_CONTEXT"
  echo "$STEPS_CONTEXT"
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
  env:
    STEPS_CONTEXT: {
    "github_step": {
      "outputs": {},
      "outcome": "Success",
      "conclusion": "Success"
    },
    "job_step": {
      "outputs": {},
      "outcome": "Success",
      "conclusion": "Success"
    },
    "arg_step": {
      "outputs": {},
      "outcome": "Failure",
      "conclusion": "Failure"
    },
    "step": {
      "outputs": {},
      "outcome": "Failure",
      "conclusion": "Failure"
    }
  }

Thank you for your feedback regarding the documentation, I'll go ahead and get that updated so we can alleviate this confusion! We should be directly stating that only steps with id:'s will have entries in the step context.

We recently added the conclusion and outcome fields, they were not available when I originally responded, but I hope they prove helpful to you!

damn, thanks, can u add it into docs?

Was this page helpful?
0 / 5 - 0 ratings