Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toJson(steps) always empty #338

Closed
rbellamy opened this issue Feb 8, 2020 · 7 comments
Closed

toJson(steps) always empty #338

rbellamy opened this issue Feb 8, 2020 · 7 comments
Labels
question Further information is requested

Comments

@rbellamy
Copy link

rbellamy commented Feb 8, 2020

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 �[36;1mecho "$STEPS_CONTEXT"�[0m
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.

@rbellamy rbellamy added the bug Something isn't working label Feb 8, 2020
@thboop
Copy link
Collaborator

thboop commented Mar 11, 2020

@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

@thboop thboop added question Further information is requested and removed bug Something isn't working labels Mar 11, 2020
@afwn90cj93201nixr2e1re
Copy link

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

@afwn90cj93201nixr2e1re
Copy link

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?

@afwn90cj93201nixr2e1re
Copy link

изображение
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"'}

@thboop
Copy link
Collaborator

thboop commented Apr 28, 2020

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!

@afwn90cj93201nixr2e1re
Copy link

damn, thanks, can u add it into docs?

@smlgbl
Copy link

smlgbl commented Jan 12, 2022

I realize this is late, but can you explain the reasoning behind this, @thboop?
I mean they all have a name already - why do I need an ID instead? And why do I need an ID to make them enumerable?
It just seems to add unnecessary clutter to each and every workflow...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants