Using output from a previous job in a new one in a GitHub Action

Check the “GitHub Actions: New workflow features” from April 2020, which could help in your case (to reference step outputs from previous jobs)

Job outputs

You can specify a set of outputs that you want to pass to subsequent jobs and then access those values from your needs context.

See documentation:

jobs.<jobs_id>.outputs

A map of outputs for a job.

Job outputs are available to all downstream jobs that depend on this job.
For more information on defining job dependencies, see jobs.<job_id>.needs.

Job outputs are strings, and job outputs containing expressions are evaluated on the runner at the end of each job. Outputs containing secrets are redacted on the runner and not sent to GitHub Actions.

To use job outputs in a dependent job, you can use the needs context.
For more information, see “Context and expression syntax for GitHub Actions.”

To use job outputs in a dependent job, you can use the needs context.

Example

jobs:
  job1:
    runs-on: ubuntu-latest
    # Map a step output to a job output
    outputs:
      output1: ${{ steps.step1.outputs.test }}
      output2: ${{ steps.step2.outputs.test }}
    steps:
    - id: step1
      run: echo "test=hello" >> $GITHUB_OUTPUT
    - id: step2
      run: echo "test=world" >> $GITHUB_OUTPUT
  job2:
    runs-on: ubuntu-latest
    needs: job1
    steps:
    - run: echo ${{needs.job1.outputs.output1}} ${{needs.job1.outputs.output2}}

Note the use of $GITHUB_OUTPUT, instead of the older ::set-output now (Oct. 2022) deprecated.

To avoid untrusted logged data to use set-state and set-output workflow commands without the intention of the workflow author we have introduced a new set of environment files to manage state and output.


Jesse Adelman adds in the comments:

This seems to not work well for anything beyond a static string.
How, for example, would I take a multiline text output of step (say, I’m running a pytest or similar) and use that output in another job?

  • either write the multi-line text to a file (jschmitter’s comment)
  • or base64-encode the output and then decode it in the next job (Nate Karasch’s comment)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)