Sub topic 9
Passing results between jobs with outputs
This chapter assumes you can read GitHub Actions workflow YAML and know what needs and if do at a basic level. Each job runs on its own runner, so a job cannot read another job's shell variables or files. Job outputs are the way to hand a small value from one job to the next. In a monorepo, that value is usually the answer to "did this area change?"
The working model
An output moves through three steps:
- A step writes a value to the file named by
$GITHUB_OUTPUT. - The job maps that step output to a job output under
jobs.<id>.outputs. - A downstream job lists the producer in
needsand readsneeds.<id>.outputs.<name>.
A minimal example
This workflow computes a value in one job and uses it in another. It needs no third-party action.
name: outputs-demo
on:
pull_request:
jobs:
detect:
runs-on: ubuntu-latest
outputs:
area: ${{ steps.pick.outputs.area }}
steps:
- id: pick
run: echo "area=backend" >> "$GITHUB_OUTPUT"
use:
needs: detect
runs-on: ubuntu-latest
steps:
- run: echo "Area is ${{ needs.detect.outputs.area }}"The id: pick on the step is what makes steps.pick.outputs.area resolvable. The job-level outputs block is the bridge. Without it, the value stays inside the detect job.
Outputs are always strings
Every output is stored as a string. A boolean-looking value such as true is the text "true". This is why the monorepo workflows in this tutorial compare against a quoted string:
if: needs.changes.outputs.backend == 'true'Writing if: needs.changes.outputs.backend is a common mistake. The string "false" is not empty, but it is easy to misread what an expression coerces to. Compare explicitly.
How the path filter action uses outputs
The dorny/paths-filter action writes one output per filter name, each set to 'true' or 'false'. It also writes a changes output holding a JSON array of the matching filter names. The change-detection job republishes them:
changes:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'services/api/**'
frontend:
- 'apps/web/**'Later chapters build the full change-detection job. Here the point is the pattern: step output, then job output, then needs.
Common errors
| Symptom | Likely cause |
|---|---|
| The output is empty in the downstream job | The producing job has no `outputs` block, or the step has no `id`. |
| The downstream job reports an unknown `needs` reference | The producer is missing from the `needs` list. |
| An `if` on `== true` never matches | The output is the string `'true'`, not a boolean. |
| The output is lost or truncated | Values with newlines need the multiline syntax. Prefer small single-line values. |
Outputs are for small values. For files or build artifacts, use artifacts or a cache instead.
Exercise
A job named changes has a step with id: filter that sets an output backend. A job named backend-test has needs: changes but reads an empty value from needs.changes.outputs.backend. What is the most likely missing piece, and how do you compare the value in an if?
Show answer
The changes job is missing an outputs: block that maps backend: ${{ steps.filter.outputs.backend }}. Step outputs are not visible to other jobs until the job maps them. Compare as a string: if: needs.changes.outputs.backend == 'true'.