Skip to content

Commit ad6f889

Browse files
authored
EDI-ify "Passing information between jobs" (#56699)
1 parent a4fc67f commit ad6f889

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed
Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Passing information between jobs
3-
shortTitle: Pass information
3+
shortTitle: Pass job outputs
44
intro: You can define outputs to pass information from one job to another.
55
versions:
66
fpt: '*'
@@ -12,8 +12,52 @@ redirect_from:
1212
- /actions/writing-workflows/choosing-what-your-workflow-does/passing-information-between-jobs
1313
---
1414

15-
{% data reusables.actions.enterprise-github-hosted-runners %}
15+
## Defining and using job outputs
1616

17-
## Overview
17+
1. Open the workflow file containing the job you want to get outputs from.
18+
1. Use the `jobs.<job_id>.outputs` syntax to define the outputs for the job. For example, the following job defines the `output1` and `output2` outputs, which are mapped to the results of `step1` and `step2` respectively:
1819

19-
{% data reusables.actions.jobs.section-defining-outputs-for-jobs %}
20+
```yaml
21+
jobs:
22+
job1:
23+
runs-on: ubuntu-latest
24+
outputs:
25+
output1: ${{ steps.step1.outputs.test }}
26+
output2: ${{ steps.step2.outputs.test }}
27+
steps:
28+
- id: step1
29+
run: echo "test=hello" >> "$GITHUB_OUTPUT"
30+
- id: step2
31+
run: echo "test=world" >> "$GITHUB_OUTPUT"
32+
```
33+
34+
1. In a separate job where you want to access those outputs, use the `jobs.<job_id>.needs` syntax to make it dependent on the original job. For example, the following job checks that `job1` is complete before running:
35+
36+
```yaml
37+
jobs:
38+
# Assume job1 is defined as above
39+
job2:
40+
runs-on: ubuntu-latest
41+
needs: job1
42+
```
43+
44+
1. To access the outputs in the dependent job, use the `needs.<job_id>.outputs.<output_name>` syntax. For example, the following job accesses the `output1` and `output2` outputs defined in `job1`:
45+
46+
```yaml
47+
jobs:
48+
# Assume job1 is defined as above
49+
job2:
50+
runs-on: ubuntu-latest
51+
needs: job1
52+
steps:
53+
- env:
54+
OUTPUT1: ${{needs.job1.outputs.output1}}
55+
OUTPUT2: ${{needs.job1.outputs.output2}}
56+
run: echo "$OUTPUT1 $OUTPUT2"
57+
```
58+
59+
## Next steps
60+
61+
To learn more about job outputs and the `needs` context, see the following sections of [AUTOTITLE](/actions/reference/workflow-syntax-for-github-actions#jobsjob_idoutputs):
62+
* [`jobs.<job_id>.outputs`](/actions/reference/workflow-syntax-for-github-actions#jobsjob_idoutputs)
63+
* [`jobs.<job_id>.needs`](/actions/reference/workflow-syntax-for-github-actions#jobsjob_idneeds)

0 commit comments

Comments
 (0)