Skip to main content

CI/CD and automation · Intermediate · 15 min

Pass build artifacts and outputs between GitHub Actions jobs

By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · GitHub Actions (upload-artifact v7, download-artifact v8, checkout v7) · actionlint 1.7.12

You will have a GitHub Actions workflow that builds a dist/ folder once, tests and deploys those exact files in later jobs, passes the version and a checksum between jobs as outputs, and writes a build summary, with every script checked on your own machine first.

On this page

A common pipeline builds the site in one job, tests in another and deploys in a third. If each job runs its own build, the files you deploy are not the files you tested: a dependency can move between jobs, or a build can pick up a different timestamp. The fix is to build once, hand the result to the later jobs, and check that what arrives is what left.

GitHub Actions gives you two hand-off channels. An artifact carries files, such as a dist/ folder, from one job to another. An output carries a short string, such as a version number or a checksum. In this tutorial you will use both: a build job uploads dist/ and publishes its version and checksum as outputs, a test job downloads and tests the folder, and a deploy job downloads it again and refuses to continue if the checksum differs. Along the way the build writes a short table to the run's summary page.

You will write the shell scripts first and run them on your machine with stand-in files for the variables GitHub sets, so you can see each output before you push. Everything lives in a throwaway folder, ~/artifacts-demo.

Step 1 · Set up the demo folder and actionlint

Create the folder with a place for scripts and workflows:

Bash
mkdir -p ~/artifacts-demo/scripts ~/artifacts-demo/.github/workflows
cd ~/artifacts-demo

Install actionlint, which checks workflow files, including every steps.*.outputs and needs.*.outputs reference. This is version 1.7.12 from its GitHub releases. On macOS, brew install actionlint does the same. On Linux:

Bash
sudo apt update
sudo apt install -y curl ca-certificates
ARCH="$(uname -m)"
case "$ARCH" in
  x86_64) ARCH=amd64 ;;
  aarch64) ARCH=arm64 ;;
esac
mkdir -p ~/.local/bin
curl -fsSL "https://github.com/rhysd/actionlint/releases/download/v1.7.12/actionlint_1.7.12_linux_${ARCH}.tar.gz" | tar -xz -C ~/.local/bin actionlint
export PATH="$HOME/.local/bin:$PATH"

A binary installed this way gets no updates from apt. To upgrade, run the same curl line with a newer version from github.com/rhysd/actionlint/releases.

Check it worked

Bash
actionlint -version | head -n 1
ls -A ~/artifacts-demo

The first line prints 1.7.12. The listing shows .github and scripts.

Step 2 · Write the build and the checksum scripts

The build script stands in for npm run build or hugo in your own project. It writes three files into dist/ and stamps them with a version taken from the BUILD_VERSION variable:

Bash
cat > scripts/build.sh <<'SH'
#!/usr/bin/env bash
# Build the site into dist/.
set -euo pipefail
version="${BUILD_VERSION:-dev}"
rm -rf dist
mkdir -p dist/assets
cat > dist/index.html <<HTML
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Artifacts demo</title></head>
<body><h1>Artifacts demo</h1><p>Version ${version}</p><script src="assets/app.js"></script></body>
</html>
HTML
printf 'console.log("artifacts demo %s");\n' "$version" > dist/assets/app.js
printf '%s\n' "$version" > dist/version.txt
echo "Built version ${version} into dist/"
SH

The checksum script prints one SHA-256 value for a whole folder. It hashes each file, lists the hashes with the file names in a fixed order, and hashes that list, so renaming, adding or editing any file changes the result:

Bash
cat > scripts/checksum.sh <<'SH'
#!/usr/bin/env bash
# Print one SHA-256 for every file under a folder, covering names and contents.
set -euo pipefail
dir="${1:?usage: checksum.sh <folder>}"
sha() {
  if command -v sha256sum >/dev/null 2>&1; then sha256sum; else shasum -a 256; fi
}
cd "$dir"
find . -type f | LC_ALL=C sort | while IFS= read -r f; do
  printf '%s  %s\n' "$(sha < "$f" | cut -d' ' -f1)" "$f"
done | sha | cut -d' ' -f1
SH

The workflow calls these with bash scripts/..., so they do not depend on the executable bit surviving in Git.

Check it worked

Build twice with the same version and compare the checksums:

Bash
BUILD_VERSION=1.0.7 bash scripts/build.sh
FIRST="$(bash scripts/checksum.sh dist)"
BUILD_VERSION=1.0.7 bash scripts/build.sh
SECOND="$(bash scripts/checksum.sh dist)"
echo "$FIRST"
[ "$FIRST" = "$SECOND" ] && echo "same input, same checksum"
find dist -type f | sort

You see Built version 1.0.7 into dist/ twice, a 64-character hex value, then same input, same checksum, then dist/assets/app.js, dist/index.html and dist/version.txt.

Step 3 · Publish step outputs and a job summary

Inside a job, a step publishes an output by appending a name=value line to the file whose path is in $GITHUB_OUTPUT. A later step reads it as steps.<step id>.outputs.<name>. The job summary works the same way: Markdown appended to the file in $GITHUB_STEP_SUMMARY appears on the run's summary page when the step ends.

This script reads facts from dist/ and writes both:

Bash
cat > scripts/describe.sh <<'SH'
#!/usr/bin/env bash
# Write the build's version and checksum as step outputs, and a summary table.
set -euo pipefail
dir="${1:?usage: describe.sh <folder>}"
: "${GITHUB_OUTPUT:?GITHUB_OUTPUT is not set}"
: "${GITHUB_STEP_SUMMARY:?GITHUB_STEP_SUMMARY is not set}"
here="$(cd "$(dirname "$0")" && pwd)"
version="$(cat "$dir/version.txt")"
checksum="$(bash "$here/checksum.sh" "$dir")"
file_count="$(find "$dir" -type f | wc -l | tr -d ' ')"
{
  echo "version=$version"
  echo "checksum=$checksum"
} >> "$GITHUB_OUTPUT"
{
  echo "### Build $version"
  echo ""
  echo "| Item | Value |"
  echo "| --- | --- |"
  echo "| Files | $file_count |"
  echo "| Checksum | \`$checksum\` |"
} >> "$GITHUB_STEP_SUMMARY"
echo "Described $file_count files in $dir"
SH

The two : lines stop the script with a clear message if it runs anywhere the variables are missing, rather than writing to a file called nothing.

Outputs are strings, and GitHub limits them to 1 MB per job and 50 MB per run. Use them for versions, digests, URLs and yes-or-no flags. Anything larger, such as a test report, belongs in an artifact. A step summary can hold up to 1 MiB, and each job shows at most 20 step summaries.

Check it worked

Point both variables at local files and run the script, the same way the runner does:

Bash
mkdir -p .local-run
: > .local-run/outputs.txt
: > .local-run/summary.md
GITHUB_OUTPUT=.local-run/outputs.txt GITHUB_STEP_SUMMARY=.local-run/summary.md bash scripts/describe.sh dist
cat .local-run/outputs.txt
cat .local-run/summary.md
grep -q '^version=1.0.7$' .local-run/outputs.txt && echo "version output written"

The script prints Described 3 files in dist. The outputs file holds two lines, version=1.0.7 and checksum= followed by the same hex value as before. The summary file is a Markdown heading ### Build 1.0.7 and a two-row table. The last line is version output written.

Step 4 · Build once and upload dist/ as an artifact

Now the workflow. The build job runs the two scripts, uploads dist/ under the name site, and lifts the step outputs to job outputs so other jobs can read them. Step outputs stay inside their job; only the names under jobs.build.outputs cross over.

Bash
cat > .github/workflows/ci.yml <<'YAML'
name: Build once, deploy the same files

on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.describe.outputs.version }}
      checksum: ${{ steps.describe.outputs.checksum }}
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false

      - name: Build
        env:
          BUILD_VERSION: 1.0.${{ github.run_number }}
        run: bash scripts/build.sh

      - name: Describe the build
        id: describe
        run: bash scripts/describe.sh dist

      - name: Upload dist
        uses: actions/upload-artifact@v7
        with:
          name: site
          path: dist/
          retention-days: 5
          if-no-files-found: error
YAML

What the upload settings do:

  • path: dist/ uploads the folder's contents, so index.html sits at the top of the artifact. Hidden files such as dist/.well-known/ are left out unless you add include-hidden-files: true; check what they contain first.
  • retention-days: 5 deletes the artifact after five days instead of the default 90. It cannot be less than 1 or more than the limit set for your repository or organisation. Artifacts count towards your account's Actions storage, so keep build output only as long as anyone will look at it.
  • if-no-files-found: error fails the job when the build produced nothing. The default only warns, and the test job would then fail later with a less useful message.
  • The artifact is a zip. Zipping does not keep file permissions: every file comes back as 644 and every folder as 755. If you hand over a binary that must stay executable, tar it first and upload the tar file.

Check it worked

Bash
actionlint .github/workflows/ci.yml
echo "actionlint exit code: $?"

No messages and exit code 0. actionlint has checked that steps.describe exists and, for actions it has data on, that the inputs are spelled correctly.

Step 5 · Test and deploy the same files in later jobs

Add the two jobs that use the artifact. Each runs on a fresh runner, so each checks out the repository for the scripts and downloads site into dist. needs does two things: it makes the job wait until the jobs it names have succeeded, and it gives it read access to their outputs.

Rewrite the whole file so the order is exact:

Bash
cat > .github/workflows/ci.yml <<'YAML'
name: Build once, deploy the same files

on:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.describe.outputs.version }}
      checksum: ${{ steps.describe.outputs.checksum }}
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false

      - name: Build
        env:
          BUILD_VERSION: 1.0.${{ github.run_number }}
        run: bash scripts/build.sh

      - name: Describe the build
        id: describe
        run: bash scripts/describe.sh dist

      - name: Upload dist
        uses: actions/upload-artifact@v7
        with:
          name: site
          path: dist/
          retention-days: 5
          if-no-files-found: error

  test:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false

      - uses: actions/download-artifact@v8
        with:
          name: site
          path: dist

      - run: bash scripts/test.sh dist

  deploy:
    needs: [build, test]
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false

      - uses: actions/download-artifact@v8
        with:
          name: site
          path: dist

      - name: Deploy
        env:
          VERSION: ${{ needs.build.outputs.version }}
          EXPECTED_CHECKSUM: ${{ needs.build.outputs.checksum }}
        run: |
          echo "Deploying version $VERSION"
          bash scripts/deploy.sh dist "$EXPECTED_CHECKSUM"
YAML

Points to notice:

  • deploy lists build in needs even though test already waits for it. A job can only read outputs of jobs it names directly.
  • The outputs reach the shell through env, not by writing ${{ needs.build.outputs.version }} inside run. An expression inside run is pasted into the script before it runs, so an unexpected value becomes code. Through env it stays a value.
  • download-artifact@v8 checks the download against the digest GitHub recorded at upload and fails the step if they differ. The checksum from the build job is a second, end-to-end check that you control: it compares the files the deploy step is about to ship with the files the build described.
  • Pull requests run build and test only. The if on deploy keeps it to pushes to main.

Now write the two scripts those jobs call. The test checks the page against the version it was built for:

Bash
cat > scripts/test.sh <<'SH'
#!/usr/bin/env bash
# Check the built site in a folder.
set -euo pipefail
dir="${1:?usage: test.sh <folder>}"
fail() { echo "FAIL: $1"; exit 1; }
[ -f "$dir/index.html" ] || fail "index.html is missing"
[ -f "$dir/assets/app.js" ] || fail "assets/app.js is missing"
version="$(cat "$dir/version.txt")"
grep -q "Version ${version}" "$dir/index.html" || fail "page does not show version ${version}"
echo "PASS: 3 checks on version ${version}"
SH

cat > scripts/deploy.sh <<'SH'
#!/usr/bin/env bash
# Deploy a folder only if it matches the checksum the build job published.
set -euo pipefail
dir="${1:?usage: deploy.sh <folder> <expected checksum>}"
expected="${2:?usage: deploy.sh <folder> <expected checksum>}"
here="$(cd "$(dirname "$0")" && pwd)"
actual="$(bash "$here/checksum.sh" "$dir")"
if [ "$actual" != "$expected" ]; then
  echo "Refusing to deploy: checksum ${actual} does not match the build (${expected})"
  exit 1
fi
version="$(cat "$dir/version.txt")"
echo "Checksum matches the build. Deploying version ${version}"
# Replace this line with your real deploy command, such as rsync to your server.
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
  echo "Deployed version ${version}; checksum verified." >> "$GITHUB_STEP_SUMMARY"
fi
SH

Check it worked

Bash
actionlint .github/workflows/ci.yml
echo "actionlint exit code: $?"

Exit code 0. Now break an output name on purpose, a mistake that would otherwise pass an empty string to the deploy script without any error from GitHub:

Bash
sed 's/needs\.build\.outputs\.checksum/needs.build.outputs.chksum/' .github/workflows/ci.yml > /tmp/ci-typo.yml
if actionlint /tmp/ci-typo.yml; then
  echo "expected actionlint to report the wrong output name"; false
else
  echo "actionlint caught the wrong output name"
fi
rm /tmp/ci-typo.yml

actionlint prints a message saying the property chksum is not defined, lists the outputs build does have, and the last line reads actionlint caught the wrong output name.

Step 6 · Rehearse the hand-off on your machine

On GitHub, the test and deploy jobs start with nothing but the checkout and the downloaded artifact. Copy exactly those two things into a second folder and run the later jobs' commands there, reading the checksum from the outputs file you wrote earlier:

Bash
rm -rf ~/artifacts-demo-handoff
mkdir -p ~/artifacts-demo-handoff
cp -R scripts dist ~/artifacts-demo-handoff/
EXPECTED="$(sed -n 's/^checksum=//p' .local-run/outputs.txt)"
cd ~/artifacts-demo-handoff
bash scripts/test.sh dist
bash scripts/deploy.sh dist "$EXPECTED"

Then change one byte in the copy, the kind of drift a second build or a stray edit would cause, and try again:

Bash
echo "<!-- edited -->" >> dist/index.html
if bash scripts/deploy.sh dist "$EXPECTED"; then
  echo "expected the deploy to refuse"; false
else
  echo "deploy refused files that differ from the build"
fi
cd ~/artifacts-demo

Check it worked

The first block prints PASS: 3 checks on version 1.0.7, then Checksum matches the build. Deploying version 1.0.7. The second prints a Refusing to deploy line showing two different checksums, then deploy refused files that differ from the build.

Step 7 · Upload from several jobs without name clashes

Since version 4 of the artifact actions, an artifact cannot be changed once it is uploaded, and two jobs in one run cannot upload under the same name. A matrix job that uploads name: report from every leg fails on the second leg. Give each leg its own name, then collect them with a pattern:

Bash
cat > .github/workflows/reports.yml <<'YAML'
name: Reports

on:
  pull_request:

permissions:
  contents: read

jobs:
  check:
    strategy:
      matrix:
        suite: [unit, links]
    runs-on: ubuntu-latest
    steps:
      - name: Write a report
        env:
          SUITE: ${{ matrix.suite }}
        run: |
          mkdir -p report
          echo "$SUITE suite passed" > "report/$SUITE.txt"

      - uses: actions/upload-artifact@v7
        with:
          name: report-${{ matrix.suite }}
          path: report/
          retention-days: 1

  collect:
    needs: check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v8
        with:
          pattern: report-*
          merge-multiple: true
          path: reports

      - name: Summarise
        run: |
          {
            echo "### Reports"
            echo ""
            for f in reports/*.txt; do
              echo "- $(cat "$f")"
            done
          } >> "$GITHUB_STEP_SUMMARY"
YAML

pattern: report-* downloads every artifact whose name starts with report-, and merge-multiple: true puts their files in one reports folder instead of one subfolder per artifact. That works here because each leg writes a different file name; two files with the same name would collide.

If you do need to replace an artifact in the same run, overwrite: true on the upload deletes the old one first. The new upload gets a new ID, so links to the old one stop working.

Check it worked

Bash
actionlint .github/workflows/reports.yml
echo "actionlint exit code: $?"

No messages and exit code 0.

Step 8 · Choose between an artifact and a cache, then run it

Artifacts and caches both store files on GitHub, but they do different jobs:

  • An artifact belongs to one workflow run. Use it to pass the output of this run to later jobs in the same run, or to keep files people will open afterwards, such as a build, a coverage report or a failing test's screenshots. Nothing restores it into the next run on its own.
  • A cache is shared between runs and looked up by a key. Use it for things that are slow to fetch and safe to lose, such as downloaded packages. A job must still work when the cache misses.

So dist/ from this commit is an artifact, and node_modules for this lock file is a cache. Caching dist/ would risk deploying a build from an older commit; uploading node_modules as an artifact on every run would cost storage and time for files a cache handles better.

Now move the work into your own repository. So far everything sits in ~/artifacts-demo, which is not a Git repository, so git add there would fail. Copy only scripts and .github into your clone, leaving dist/ and .local-run/ behind.

Before you copy, check your repository: the copy overwrites any existing .github/workflows/ci.yml or .github/workflows/reports.yml and any scripts called build.sh, checksum.sh, describe.sh, test.sh or deploy.sh in scripts/. If those names are taken, rename the new files first. Also note that reports.yml runs only on pull requests, so it does nothing on this push.

Replace <your-repo> with the path to your clone, then copy, commit and push to main:

Bash
cp -R scripts .github ~/<your-repo>/
cd ~/<your-repo>
git status
git add scripts .github/workflows/ci.yml .github/workflows/reports.yml
git commit -m "Build once and pass dist between jobs"
git push

git status should list only the new scripts and the two workflow files. If you ever build inside your clone, add dist/ and .local-run/ to its .gitignore so they are never committed.

If your team works on prepaid mobile data, as many developers in Nigeria and across Africa do, note that downloading an artifact to your laptop pulls the full zip. Keep build artifacts small, and use the run's summary page to read results instead of downloading reports.

Check it worked

Open the run in the repository's Actions tab. You see three jobs joined by lines: build, then test, then deploy. The run's summary page shows the Build 1.0.<run number> table and the line Deployed version ...; checksum verified., and lists one artifact called site with its size and an expiry date five days out. On a pull request, deploy shows as skipped.

To fetch the same files the deploy job shipped, replace <run-id> with the number in the run's URL:

Bash
gh run download <run-id> --name site --dir site-from-ci

The folder site-from-ci holds index.html, version.txt and assets/app.js.

When you have finished with the demo, remove the folders and the actionlint binary if you installed it only for this:

Bash
cd ~
rm -rf ~/artifacts-demo ~/artifacts-demo-handoff
rm -f ~/.local/bin/actionlint

Next steps

  • Cache the dependencies the build job installs, under keys you design: /tutorials/cache-dependencies-and-build-outputs-in-github-actions
  • Replace the stand-in deploy line with a real copy to your server: /tutorials/deploy-to-a-server-over-ssh-with-github-actions
  • Move the build-and-upload steps into a reusable workflow that several repositories call: /tutorials/write-reusable-workflows-and-composite-actions
  • Name artifacts per leg when you build across systems and versions: /tutorials/run-a-build-matrix-across-operating-systems-and-versions

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.