| title | Passing information between jobs | ||||||
|---|---|---|---|---|---|---|---|
| shortTitle | Pass job outputs | ||||||
| intro | You can define outputs to pass information from one job to another. | ||||||
| versions |
|
||||||
| redirect_from |
|
||||||
| category |
|
||||||
| contentType | how-tos |
-
Open the workflow file containing the job you want to get outputs from.
-
Use the
jobs.<job_id>.outputssyntax to define the outputs for the job. For example, the following job defines theoutput1andoutput2outputs, which are mapped to the results ofstep1andstep2respectively:jobs: job1: runs-on: ubuntu-latest outputs: output1: {% raw %}${{ steps.step1.outputs.test }}{% endraw %} output2: {% raw %}${{ steps.step2.outputs.test }}{% endraw %} steps: - id: step1 run: echo "test=hello" >> "$GITHUB_OUTPUT" - id: step2 run: echo "test=world" >> "$GITHUB_OUTPUT"
-
In a separate job where you want to access those outputs, use the
jobs.<job_id>.needssyntax to make it dependent on the original job. For example, the following job checks thatjob1is complete before running:jobs: # Assume job1 is defined as above job2: runs-on: ubuntu-latest needs: job1
-
To access the outputs in the dependent job, use the
needs.<job_id>.outputs.<output_name>syntax. For example, the following job accesses theoutput1andoutput2outputs defined injob1:jobs: # Assume job1 is defined as above job2: runs-on: ubuntu-latest needs: job1 steps: - env: OUTPUT1: {% raw %}${{needs.job1.outputs.output1}}{% endraw %} OUTPUT2: {% raw %}${{needs.job1.outputs.output2}}{% endraw %} run: echo "$OUTPUT1 $OUTPUT2"
To learn more about job outputs and the needs context, see the following sections of AUTOTITLE:
To learn more about passing job outputs from one workflow to another, see the following section of AUTOTITLE: