6

I have a workflow that executes a bunch of fuzz tests and, at the end, calculates the total number of files in all crashers sub-directories. Later, in another job, I use that number to send a notification to Slack. But, for some reason, ::set-output produces no output and, most importantly, the next job does not get run even though the number of crashers is not zero!

jobs:
  fuzz-nightly-test:
    runs-on: ubuntu-latest
    steps:
      ...
      - name: Set crashers count
        working-directory: test/fuzz
        run: echo "::set-output name=crashers-count::$(find . -type d -name 'crashers' | xargs -I % sh -c 'ls % | wc -l' | awk '{total += $1} END {print total}')"
        id: set-crashers-count

   outputs:
     crashers-count: ${{ steps.set-crashers-count.outputs.crashers-count }}

  fuzz-nightly-fail:
    needs: fuzz-nightly-test
    if: ${{ needs.set-crashers-count.outputs.crashers-count != 0 }}
    runs-on: ubuntu-latest
    steps:
      ...

Does anybody know what I am doing wrong? Thank you!

2 Answers 2

16
+50

I did a bunch of tests with a similar minimal example and I think I figured out the issue. Most immediately, in your if directive in your fuzz-nightly-fail job, you need to be accessing needs.<job_id>.outputs.<job_output_id> rather than needs.<step_id>.outputs.<job_output_id>. Therefore, the if directive would become if: ${{ needs.fuzz-nightly-test.outputs.crashers-count != 0 }}.

Additionally, you should probably make a step output ID that's distinct from the job output ID to save yourself from some confusion about what context object is being referenced where. So, the run statement in your first job could be something like run: echo "::set-output name=count::$(find . -type d -name 'crashers' | xargs -I % sh -c 'ls % | wc -l' | awk '{total += $1} END {print total}')" and the job output would also be changed to crashers-count: ${{ steps.set-crashers-count.outputs.count }}. Putting this all together, we get

jobs:
  fuzz-nightly-test:
    runs-on: ubuntu-latest
    steps:
      ...
      - name: Set crashers count
        working-directory: test/fuzz
        run: echo "::set-output name=count::$(find . -type d -name 'crashers' | xargs -I % sh -c 'ls % | wc -l' | awk '{total += $1} END {print total}')"
        id: set-crashers-count

   outputs:
     crashers-count: ${{ steps.set-crashers-count.outputs.count }}

  fuzz-nightly-fail:
    needs: fuzz-nightly-test
    if: ${{ needs.fuzz-nightly-test.outputs.crashers-count != 0 }}
    runs-on: ubuntu-latest
    steps:
      ...

The reason for this isn't immediately obvious from the documentation alone, but the example here implies that <step_id>.outputs.foo is different from <job_id>.outputs.foo - jobs.job1.outputs.output1 is defined as that job's steps.step1.outputs.test.

You can see a (very) minimal example of this here, with its corresponding workflow run here.

Sign up to request clarification or add additional context in comments.

1 Comment

wow, thanks for pointing my mistake! should've notice that too.
0

Same issue was faced so when searched in intervet got the solution saying

jobs:
  prepare-matrix:
    runs-on: ubuntu-latest
    outputs:
      platforms: ${{ steps.platform-matrix.outputs.matrix }}
      regions: ${{ steps.region-matrix.outputs.matrix }}
    steps:
      # Step 1: Retrieve and parse PLATFORMS
      - name: Platform Matrix
        id: platform-matrix
        env:
          PLATFORMS: ${{ vars.variablename }}
        run: |
          # Convert the repository variable to JSON array
          MATRIX_JSON=$(jq -nc --arg values "$PLATFORMS" '$values | split(",")')
          echo "::set-output name=matrix::$MATRIX_JSON"

Changed the set-output line with below line

echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT

The code ran perfectly . Same is also communicated here : https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.