Pass data between jobs in GitHub Actions: GITHUB_OUTPUT
Pass a value or a file between steps and jobs: $GITHUB_OUTPUT, job outputs with needs, $GITHUB_ENV, artifacts, matrix outputs and size limits.
In this series24 guides, you're on Passing data
Most non-trivial workflows need to move a value from one place to another: a version number computed in one step, a build matrix generated by an early job, a compiled binary handed off to a deploy job. GitHub Actions gives you a few distinct mechanisms for this, and picking the right one matters. In this article you’ll learn the modern, supported ways to pass data — between steps in the same job, between separate jobs, and across entire runs — along with when to reach for each.
A quick note before we start: if you’ve seen older tutorials using ::set-output:: or ::save-state::, those workflow commands are deprecated. As of November 2026 they still work, but the runner can log a warning that they will be disabled. Use the environment files instead: everything below uses $GITHUB_OUTPUT and $GITHUB_ENV, and $GITHUB_STATE replaces save-state inside actions.
Step outputs: passing data between steps with $GITHUB_OUTPUT#
The smallest unit of data passing is a step output. A step writes a name=value pair to the special file referenced by $GITHUB_OUTPUT, and later steps read it back through the steps context — as long as the producing step has an id.
name: Step outputs
on: push
jobs: build: runs-on: ubuntu-latest steps: - name: Compute a version id: version run: echo "value=1.4.2" >> "$GITHUB_OUTPUT"
- name: Use the version env: VERSION: ${{ steps.version.outputs.value }} run: echo "Building version $VERSION"The key pieces:
- The producing step must declare an
id(versionabove). Without it, there’s no handle to read from. - You append
name=valueto$GITHUB_OUTPUT— always quote the variable so a path with spaces won’t break. In PowerShell, the default shell on Windows runners, append to$env:GITHUB_OUTPUTinstead ("value=1.4.2" >> $env:GITHUB_OUTPUT), or setshell: bashon the step. - Downstream steps read it with
${{ steps.<id>.outputs.<name> }}. In a script, pass it throughenv:as above rather than writing${{ }}insiderun:. The expression is pasted into the script before it runs, so quotes or untrusted text in the value can break the script or inject commands into it. - Since June 2026, a step can run with
background: true. Its outputs reach later steps only after awaitorwait-allthat includes it (see parallel steps).
This replaces the old echo "::set-output name=value::1.4.2" command, which is deprecated.
Multiline and structured values#
A single name=value line can’t hold a value that contains newlines — think a JSON document, a changelog, or multi-line command output. For those, GitHub Actions supports a heredoc-style delimiter syntax: write name<<DELIMITER, then the value, then the delimiter again on its own line.
- name: Emit JSON output id: meta run: | { echo "json<<EOF" cat data.json echo "EOF" } >> "$GITHUB_OUTPUT"Here the whole block is grouped with { ... } >> "$GITHUB_OUTPUT" so every echo and the cat get appended to the file together. Pick a delimiter (EOF is conventional) that’s guaranteed not to appear inside the value — if you’re not sure, use a random string.
The closing delimiter must start its own line, so the value has to end with a newline. A file written by a program often doesn’t, and the step then fails with Matching delimiter not found. Use printf '%s\n' "$(cat data.json)" in place of cat data.json to add the newline, or, for JSON, skip the delimiter and compact it to one line: echo "json=$(jq -c . data.json)" >> "$GITHUB_OUTPUT".
Either way, you consume it like any other output, and parse it with fromJson if it’s JSON:
- name: Read a field from the JSON env: NAME: ${{ fromJson(steps.meta.outputs.json).name }} run: echo "$NAME"Job outputs: passing data between jobs#
Step outputs live and die within a single job. To hand a value to a different job, you promote a step output to a job output using the job’s outputs: map, and the downstream job reads it through the needs context.
There are three requirements, and missing any one of them is the usual reason this “doesn’t work”:
- The producing step has an
idand writes to$GITHUB_OUTPUT. - The producing job declares an
outputs:map that references that step output. - The consuming job declares
needs: <producing-job>— this both creates the dependency and makesneeds.<job>.outputsavailable. Only direct dependencies count: a job further down the graph lists the producing job too (needs: [prepare, build]).
Here’s a complete two-job example:
name: Job outputs
on: push
jobs: prepare: runs-on: ubuntu-latest outputs: version: ${{ steps.version.outputs.value }} steps: - name: Compute a version id: version run: echo "value=1.4.2" >> "$GITHUB_OUTPUT"
deploy: runs-on: ubuntu-latest needs: prepare steps: - name: Deploy that version env: VERSION: ${{ needs.prepare.outputs.version }} run: echo "Deploying $VERSION"The deploy job won’t start until prepare succeeds, and it reads the value with ${{ needs.prepare.outputs.version }}. A common real-world use of this pattern is generating a dynamic matrix in one job and consuming it in another — covered in the matrix strategy article.
A step that uses an action exposes the action’s outputs the same way, as steps.<id>.outputs.<name>, so you can promote those too. A reusable workflow passes data back by mapping its job outputs to on.workflow_call.outputs, and the caller’s later jobs read them with needs.<calling-job>.outputs.<name>.
A masked value can’t be a job output. When a job output contains a secret or a value masked with add-mask, the runner skips it with the warning Skip output '<name>' since it may contain secret., and the next job reads an empty string. To pass a secret between jobs, keep it in a secret store and pass only a handle to it as the output, as in GitHub’s example ↗.
Outputs from a matrix job#
All the jobs of a matrix share one set of job outputs, so when several of them write the same output name, the last one to finish wins. To collect one value per matrix job, give each its own output name, or have each job upload a small artifact and merge them downstream:
jobs: test: strategy: matrix: shard: [1, 2, 3] runs-on: ubuntu-latest steps: - run: echo "shard ${{ matrix.shard }} ok" > "result-${{ matrix.shard }}.txt" - uses: actions/upload-artifact@v7 with: name: result-${{ matrix.shard }} path: result-${{ matrix.shard }}.txt
report: needs: test runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v8 with: pattern: result-* merge-multiple: true # all files in one directory - run: cat result-*.txtJob outputs have a size limit#
Job outputs are meant for small string data — version numbers, flags, JSON blobs, image tags. They are not a file-transfer channel. GitHub caps outputs at 1 MB per job and 50 MB total per workflow run (measured on UTF-16 encoding). If you try to pass a compiled artifact or a large dataset this way, you’ll hit those limits. For anything file-shaped or large, use artifacts instead.
$GITHUB_ENV: environment variables for later steps in the same job#
$GITHUB_OUTPUT is for values you address by name. $GITHUB_ENV is for values you want available as environment variables in every subsequent step of the same job. This is convenient when several later steps all need the same value and you’d rather not repeat a steps.<id>.outputs expression everywhere:
steps: - name: Set an env var run: echo "BUILD_ID=$(date +%s)" >> "$GITHUB_ENV"
- name: Use it run: echo "Build is $BUILD_ID"The environment variables guide has the details in Setting a variable from a step: which steps see the variable, multi-line values and how to mask a value you computed.
Artifacts: passing files and large data between jobs#
When the thing you need to pass is a file — a compiled binary, a coverage report, a tarball, a built site — job outputs are the wrong tool. Upload it as an artifact in one job and download it in another. Artifacts handle binary data and have far larger limits than job outputs.
name: Build and deploy
on: push
jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - name: Build run: | mkdir -p dist npm ci && npm run build
- name: Upload build output uses: actions/upload-artifact@v7 with: name: dist path: dist/
deploy: runs-on: ubuntu-latest needs: build steps: - uses: actions/checkout@v7 - name: Download build output uses: actions/download-artifact@v8 with: name: dist path: dist/
- name: Deploy run: ./deploy.sh dist/Each job starts with an empty workspace, so deploy checks out the repository to get deploy.sh. The checkout comes first: actions/checkout empties a workspace that isn’t a Git repository, so it would delete files downloaded before it.
Artifacts are kept for 90 days by default, so they’re also how you make build outputs downloadable from the run’s summary page. The repository, organization or enterprise setting changes that period (1 to 90 days in public repositories, up to 400 in private ones), and retention-days on the upload sets a shorter one. In a private repository, retention-days: 1 on an artifact that only hands files to the next job limits how long it counts against your artifact storage. Since October 2026, the retention setting also deletes the workflow runs themselves, with their checks and commit statuses.
Things to know about the current artifact actions (v4 and later):
- Names are unique per run and artifacts are immutable. Uploading to an existing name fails, unless you set
overwrite: true. Matrix jobs need a name per job (dist-${{ matrix.os }}), thenpatternto download them together. Withoutmerge-multiple, each artifact lands in a directory named after it (dist-ubuntu-latest/,dist-windows-latest/). Usemerge-multiple: true, as above, only when each job’s files have distinct names: files with the same name overwrite each other. - Single files without a zip. With upload-artifact v7,
archive: falseuploads one file as-is, so it downloads from the UI without being wrapped in a zip. The artifact takes the file’s name andnameis ignored, so download it by the file name. - Executable bits are lost. A zipped artifact comes back with every file at mode
644, so a compiled binary is no longer executable. Runchmod +xafter the download, ortarthe files and upload the tarball witharchive: false. - Downloads are checked.
download-artifactv8 compares each downloaded artifact’s SHA-256 digest with the one recorded at upload and fails the step on a mismatch. Itsdigest-mismatchinput (ignore,info,warnorerror, the default) changes that. - Hidden files are skipped. Files and directories whose names start with a dot (
.nojekyll,.htaccess, a.next/build) are left out unless you setinclude-hidden-files: true. - From another run or workflow.
download-artifacttakesrun-idandgithub-token(withactions: read) to fetch artifacts from a different run, which is how aworkflow_runworkflow gets the build’s output. - The job’s
GITHUB_TOKENisn’t needed for the same run. Within one run, upload and download need no extra permissions.
Choosing the right tool#
These mechanisms overlap a little, but each has a clear sweet spot:
| Need | Use | How it travels |
|---|---|---|
| A value in later steps of the same job | $GITHUB_ENV | Environment variable, subsequent steps only |
| A named value in later steps of the same job | $GITHUB_OUTPUT (step output) | steps.<id>.outputs.<name> |
| Small string data between jobs | Job outputs: + needs | needs.<job>.outputs.<name> (≤1 MB/job) |
| Files or large/binary data between jobs | Artifacts | upload-artifact → download-artifact |
| Data reused across separate runs | Cache | actions/cache, keyed restore |
A rough decision flow: within a job, reach for $GITHUB_ENV or step outputs. Between jobs, use job outputs for a small string and artifacts for anything file-shaped or over the size limit. And if you want the same data to survive from one workflow run to the next — dependencies, build caches — that’s caching, covered in the caching article.
Conclusion#
Passing data in GitHub Actions comes down to matching the mechanism to the distance and shape of the data: $GITHUB_ENV and step outputs stay inside a job, job outputs carry small strings across the needs graph, artifacts move files between jobs, and caching carries data across runs. Stick to the environment-file syntax (>> "$GITHUB_OUTPUT" and >> "$GITHUB_ENV"), use the heredoc delimiter trick for multiline values, mask anything sensitive, and you’ll have clean, predictable data flow through even complex pipelines.