You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{% data reusables.actions.enterprise-github-hosted-runners %}
15
+
## Defining and using job outputs
16
16
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:
18
19
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):
0 commit comments