Working with Job Outputs
1. Setting Job Outputs
| Property | Description | Values | Notes |
|---|---|---|---|
| name | Name of the output | string |
Must be unique within the job |
| value | Value to set as output | string |
Can reference environment variables or context expressions |
Example: Setting a job output
jobs:
build:
steps:
- name: Set output
id: set_output
run: echo "result=success" >> $GITHUB_OUTPUT
Example: Using job outputs in downstream jobs
jobs:
build:
outputs:
result: ${{ steps.set_output.outputs.result }}
steps:
- id: set_output
run: echo "result=success" >> $GITHUB_OUTPUT
deploy:
needs: build
steps:
- run: echo "Deploying result: ${{ needs.build.outputs.result }}"
2. Setting Output from Step
| Property | Description | Values | Notes |
|---|---|---|---|
| name | Name of the output | string |
Used to reference the output in later steps or jobs |
| value | Value to set as output | string |
Can be any string or expression |
Example: Setting a Step Output
jobs:
build:
steps:
- name: Set output
id: set_output
run: echo "result=success" >> $GITHUB_OUTPUT
- name: Use output
run: echo "The result was ${{ steps.set_output.outputs.result }}"
Note: Outputs are only available to subsequent steps in the same job or to jobs that depend on this job.
3. Accessing Outputs in Dependent Jobs
| Property | Description | Usage |
|---|---|---|
| job.outputs | Defines outputs for a job | |
| steps.<step_id>.outputs | Defines outputs from a step | |
Example: Accessing Job Outputs
jobs:
build:
outputs:
version: ${{ steps.set_version.outputs.version }}
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy with version
run: echo "Deploying version ${{ needs.build.outputs.version }}"
Note: Outputs are only available to jobs that
needs the job that defines them.4. Using Multiline Outputs
| Property | Description | Usage |
|---|---|---|
| outputs | Defines the output values that a job can return | |
Example: Setting Multiline Output
jobs:
build:
steps:
- name: Set multiline output
id: set_output
run: |
echo "result=Line 1
Line 2
Line 3" >> $GITHUB_OUTPUT
Example: Using Multiline Output in Another Job
jobs:
build:
outputs:
multiline_result: ${{ steps.set_output.outputs.result }}
steps:
- name: Set multiline output
id: set_output
run: |
echo "result=Line 1
Line 2
Line 3" >> $GITHUB_OUTPUT
consume:
needs: build
steps:
- name: Use multiline output
run: echo "${{ needs.build.outputs.multiline_result }}"
5. Passing Outputs Between Jobs
| Property | Description | Example |
|---|---|---|
| jobs.<job_id>.outputs | Defines outputs for a job that can be used by other jobs | |
| jobs.<job_id>.outputs.<output_name> | Name of the output variable to be used in downstream jobs | |
| steps.<step_id>.outputs | Defines outputs from a step that can be used in downstream jobs | |
Example: Passing Outputs Between Jobs
name: Build and Deploy
on: [push]
jobs:
build:
runs-on: ubuntu-latest
outputs:
build_id: ${{ steps.build-step.outputs.build_id }}
steps:
- name: Build Step
id: build-step
run: |
echo "build_id=12345" >> $GITHUB_OUTPUT
- name: Output Build ID
run: echo "Build ID is ${{ steps.build-step.outputs.build_id }}"
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy Step
run: echo "Deploying build ${{ jobs.build.outputs.build_id }}"
Note: Outputs are only available to jobs that depend on the job that defines them.
6. Using Outputs in Conditions
| Property | Description | Usage |
|---|---|---|
| job.outputs | Defines outputs from a job that can be used in conditions | outputs.<key> |
Example: Using job outputs in conditions
jobs:
build:
outputs:
build-success: ${{ job.status }}
deploy:
needs: build
if: ${{ jobs.build.outputs.build-success == 'success' }}
steps:
- run: echo "Deploying..."
Note: The
job.status is a built-in property that can be used to determine job success or failure.
7. Setting Multiple Outputs
Example: Setting Multiple Job Outputs
jobs:
build:
outputs:
job_output1: ${{ jobs.build.outputs.job_output1 }}
job_output2: ${{ jobs.build.outputs.job_output2 }}
steps:
- name: Set multiple outputs
id: set_outputs
run: |
echo "job_output1=success" >> $GITHUB_OUTPUT
echo "job_output2=failed" >> $GITHUB_OUTPUT
| Property | Description | Values |
|---|---|---|
| outputs | Defines the outputs for a job | object |
| job_output1 | First output value from the job | string |
| job_output2 | Second output value from the job | string |
Note: Outputs are available in subsequent jobs using
jobs.<job_id>.outputs.<output_name>.
8. Using Outputs in Matrix
| Property | Description | Example |
|---|---|---|
| strategy.matrix | Defines the matrix of job configurations to run | {"os": ["ubuntu-latest", "windows-latest"], "node-version": ["18.x", "20.x"]} |
| outputs | Defines the outputs to be made available to subsequent jobs | {"matrix-output": "${{ matrix.os }}-${{ matrix.node-version }}"} |
Example: Using Matrix Outputs in a Subsequent Job
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [18.x, 20.x]
outputs:
matrix-output: ${{ matrix.os }}-${{ matrix.node-version }}
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Build
run: npm run build
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy using matrix output
run: echo "Deploying ${{ needs.build.outputs.matrix-output }}"
Note: The
outputs in a matrix job must be defined using matrix variables to ensure each job's output is unique.9. Debugging Output Values
Example: Using echo to debug output values
echo "The output value is: ${{ steps.step1.outputs.my_output }}"
| Property | Description | Usage |
|---|---|---|
| outputs | Defines the output values that a job can use | outputs.my_output |
| step.outputs | Reference to an output from a previous step | ${{ steps.step1.outputs.my_output }} |
Note: Use
echo or echo "Value: ${{ outputs.my_output }}" to inspect values during workflow runs.Warning: Output values are only available after the step that sets them completes successfully.
10. Handling Empty Outputs
| Property | Description | Notes |
|---|---|---|
| outputs | Defines the output values of a job | Can be empty or undefined if no outputs are set |
| steps | Each step can define its own outputs | If a step does not produce an output, it is omitted from the job's outputs |
Example: Setting Empty Outputs
jobs:
build:
outputs:
empty_output: ${{ jobs.build.outputs.empty_output }}
steps:
- name: Set Empty Output
id: set_empty
run: echo "No output here"
Note: When a job has no outputs defined, it will not produce any output variables that can be used in downstream jobs.
11. Using Outputs Across Workflows
| Property | Description | Usage |
|---|---|---|
| job.outputs | Defines outputs for a job that can be used by other jobs in the same workflow or in downstream workflows. | outputs: is a top-level key within a job definition. |
| steps.<step-id>.outputs | Defines outputs from a specific step, which can then be referenced in other steps or jobs. | Used inside a step definition under outputs. |
Example: Defining job outputs in a workflow
jobs:
build:
outputs:
build_id: ${{ jobs.build.outputs.build_id }}
steps:
- name: Build
id: build_step
run: echo "build_id=12345" >> $GITHUB_OUTPUT
Example: Using outputs in a downstream workflow
jobs:
publish:
needs: build
steps:
- name: Use output from build job
run: echo "Build ID is ${{ needs.build.outputs.build_id }}"
Note: Outputs are only available to workflows that are triggered by the same event and run after the current workflow completes.
12. Type Casting Outputs
| Output | Type | Description | Example |
|---|---|---|---|
| steps.<step-id>.outputs.<output-name> | string |
Value of the output as a string | outputs: { message: "Hello, World!" } |
| steps.<step-id>.outputs.<output-name> | number |
Value of the output as a number | outputs: { count: 42 } |
| steps.<step-id>.outputs.<output-name> | boolean |
Value of the output as a boolean | outputs: { success: true } |
| steps.<step-id>.outputs.<output-name> | array |
Value of the output as an array | outputs: { items: ["item1", "item2"] } |
| steps.<step-id>.outputs.<output-name> | object |
Value of the output as an object | outputs: { config: { port: 8080 } } |
Example: Casting to String
jobs:
build:
steps:
- name: Set output
id: set-output
run: echo "message=Hello, World!" >> $GITHUB_OUTPUT
- name: Use output as string
run: echo "Output is: ${{ steps.set-output.outputs.message }}"
Example: Casting to Number
jobs:
build:
steps:
- name: Set output
id: set-output
run: echo "count=42" >> $GITHUB_OUTPUT
- name: Use output as number
run: echo "Count is: ${{ steps.set-output.outputs.count }}"
Example: Casting to Boolean
jobs:
build:
steps:
- name: Set output
id: set-output
run: echo "success=true" >> $GITHUB_OUTPUT
- name: Use output as boolean
run: echo "Success is: ${{ steps.set-output.outputs.success }}"