The build job finished in 3 minutes 40 seconds, green tick, bundle written to dist/. Thirty seconds later the test job fails on its first step: ls: cannot access 'dist': No such file or directory. The workflow file lists both jobs one under the other, the test job even has needs: build, and still the folder is gone.

Nothing is broken. GitHub Actions is doing what it was designed to do, and the fix takes about 12 lines of YAML. Understanding why it needs those lines, though, saves the next few hours of debugging: lost executable bits, artifacts that clash in matrix builds, and storage bills that grow quietly with every push.

Why the second job cannot see the first job's files

Every job in a workflow gets its own runner. On GitHub-hosted runners that means a fresh virtual machine, provisioned for that job and discarded when it ends. Two jobs in the same workflow, even with one depending on the other, never share a disk. The needs keyword controls order and passes job outputs and results; it does not copy a single file.

Steps are different. Steps inside one job run on the same machine, one after another, in the same working directory, so a file written in step 2 is visible in step 5. That is why the fastest fix for small workflows is often to merge build and test into a single job. You give up parallelism and a clean separation in the UI, but you skip the upload and download entirely.

When the jobs need to stay separate, for example because tests run in a matrix of 6 Node versions, or a deploy job needs approval through an environment, files must leave the first runner and arrive on the next.

Artifacts are the built-in channel for that, implemented by two official actions: actions/upload-artifact and actions/download-artifact, both on major version 4 since late 2023. Self-hosted runners can keep files on disk between jobs, but relying on that ties the workflow to one machine and breaks as soon as a second runner joins the pool.

What upload-artifact does with your paths

The upload action zips the files you name and sends them to storage attached to the workflow run. Its behaviour around paths is the first place people get surprised.

Artifact: a named, zipped bundle of files stored with a workflow run, downloadable by later jobs in the same run, by other workflows that know the run ID, and by humans from the run's summary page.

Retention period: how long an artifact is kept before deletion. The default is 90 days, and it is configurable per upload with retention-days, within limits set at repository or organisation level.

Least common ancestor: when you give the action several paths, it finds the deepest directory they all share and stores files relative to that directory. That directory itself does not appear in the artifact.

That last rule explains a classic confusion. Upload dist/ alone and the artifact contains index.html and assets/, not a dist folder. Download it into the default location and you get index.html in the workspace root, so a later ls dist fails again. Either upload with a path that preserves the folder you expect, or download with path: dist.

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

Set if-no-files-found: error. The default is a warning, which means a build that silently produced nothing uploads nothing and the failure only appears two jobs later, far from its cause.

The download side: names, patterns and where files land

Download is the mirror image, with one more choice to make: which artifacts to fetch. With name, the action downloads one artifact and extracts its contents into path, or the workspace if path is absent. Without name, it downloads every artifact from the run, and each one lands in its own subdirectory named after the artifact.

Version 4 added two inputs that make multi-artifact downloads practical. pattern accepts a glob such as coverage-*, so a reporting job can pick up only the artifacts it needs. merge-multiple: true extracts all matching artifacts into the same directory instead of one folder each, which is what you want when 6 matrix jobs each produced a coverage file with a different name.

Downloads are not limited to the current run. With run-id and a github-token that has actions: read permission, a job can fetch artifacts from another workflow run, even in another repository. That is how a release workflow can reuse binaries built and tested by an earlier CI run instead of rebuilding them, which matters when the build is slow or must be reproducible.

The action unzips for you. You will not see a .zip unless you download the artifact manually from the web interface, where it always arrives zipped.

A minimal build-then-test workflow, annotated

Here is the shape that fixes the opening failure, trimmed to the parts that matter.

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - uses: actions/upload-artifact@v4
        with:
          name: web-dist
          path: dist/
          retention-days: 5
          if-no-files-found: error

  test:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/download-artifact@v4
        with:
          name: web-dist
          path: dist
      - run: npm ci && npm test

Three details carry the weight. The needs: build line guarantees the artifact exists before the test job starts; without it, both jobs start in parallel and the download fails. The download step names the artifact and sets path: dist, which puts the files back where the tests expect them, compensating for the path stripping described above. And the test job runs actions/checkout again, because the source code is not on that runner either: artifacts carry only what you uploaded.

A common reflex is to upload node_modules as well, to save the second npm ci. Resist it on most projects. A dependency tree of 300 to 500 MB compresses slowly, uploads slowly and costs storage, while npm ci with a dependency cache usually restores in under 30 seconds.

Upload the build output the next job consumes, nothing more. If a later job needs the same dependencies, give it the same cache key and let it restore them itself; a cache restore that misses only costs time, while a missing artifact fails the job.

Matrix jobs and the immutability rule in v4

The biggest behavioural change in version 4 is that an artifact is immutable once uploaded. In v3, several jobs could upload into the same artifact name and the files were merged. In v4, a second upload to an existing name in the same run fails with a conflict error, unless you set overwrite: true, which replaces the artifact rather than adding to it.

Matrix builds hit this immediately. If 4 jobs, one per operating system and Node version pair, all run upload-artifact with name: test-results, only the first succeeds. The fix is to make each name unique from the matrix values and merge on download. In the workflow file you build the name with an expression that inserts matrix.os and matrix.node; the snippet below shows what one of the 4 jobs resolves it to.

- uses: actions/upload-artifact@v4
  with:
    name: test-results-ubuntu-latest-node20
    path: reports/

  # later, in the report job
- uses: actions/download-artifact@v4
  with:
    pattern: test-results-*
    merge-multiple: true
    path: all-reports

Make sure the files themselves also have unique names. With merge-multiple, two artifacts that both contain junit.xml overwrite each other in the target folder, and you lose results without any error. Writing the operating system into the file name at test time, junit-ubuntu-latest.xml and so on, avoids it. There is also a limit to keep in mind: a single job can upload at most 500 artifacts, which is rarely a problem unless a script uploads one artifact per file.

The trade made in v4 was deliberate. Immutable artifacts are available through the API and UI as soon as the upload finishes, not only after the run ends, and uploads are much faster than in v3. The cost is that workflows written for the old merge behaviour need renaming.

Artifacts travel as zip files, and zip does not preserve Unix file permissions in this pipeline. Upload a compiled binary or a shell script with the executable bit set, download it in the next job, and running it fails with Permission denied. The official documentation recommends the fix: archive the files with tar before uploading and extract after downloading, since tar keeps permissions, ownership and symlinks.

tar -czf bin.tar.gz -C build bin/
  # upload bin.tar.gz, then in the next job:
tar -xzf bin.tar.gz

A quicker alternative for one or two files is chmod +x after the download, though it is easy to forget when the list grows.

Hidden files are the second trap. Since version 4.4.0 of upload-artifact, released in 2024, files and folders starting with a dot are excluded by default, partly to stop .env files and credentials from leaking into artifacts that anyone with read access can download. If you genuinely need a .next build folder or a .npmrc, set include-hidden-files: true, and check what else that pattern picks up before you do.

Treat everything in an artifact as readable by every person who can read the repository. In a public repository that means the internet. Never upload a file you would not paste into a public issue.

Worked example: what retention and compression cost on a busy repo

Artifact storage counts against your account's GitHub Actions storage allowance, and beyond the included amount it is billed per gigabyte. The arithmetic is easy to ignore until the first bill, so here is an illustrative calculation.

A team pushes about 40 times a day across branches and pull requests. Each run uploads a 140 MB web build, a 25 MB test report and a 60 MB coverage bundle, 225 MB in total. With the 90-day default retention, storage stabilises at roughly 40 runs x 225 MB x 90 days, which is about 810 GB held at any moment. Even with an included allowance of a few gigabytes, almost all of that would be billable.

Now apply three changes. Set retention-days: 3 on the web build and the test report, since nobody downloads them after the pull request is merged; keep coverage for 14 days. Lower the build's size by uploading only dist/ and not source maps, bringing it to 90 MB. And raise compression-level from the default 6 to 9 for the text-heavy coverage files, which might bring them from 60 to 45 MB, while using level 0 for already compressed images where extra effort buys nothing.

The new steady state: 40 x (90 + 25) MB x 3 days for build and reports, about 13.8 GB, plus 40 x 45 MB x 14 days for coverage, about 25.2 GB. Total around 39 GB instead of 810 GB, a reduction of about 95 percent. Exact compression ratios vary with content, so measure your own; the retention change alone does most of the work.

Artifacts, cache or job outputs: picking the channel

Three mechanisms move data between jobs in GitHub Actions, and they are often confused.

Job outputs carry small strings: a version number, a commit SHA, a flag that says whether to deploy. You write them to the $GITHUB_OUTPUT file in a step, expose them in the job's outputs block, and read them with needs.build.outputs.version. They are limited to 1 MB per job, which rules out files but makes them ideal for decisions.

The cache, through actions/cache, is designed for reuse across runs: dependency folders, compiler caches, downloaded toolchains. Entries are keyed, shared between workflow runs on related branches, evicted after 7 days without access, and capped at 10 GB per repository by default. It is a performance tool. A cache miss must never break the build, so it is the wrong place for a build product a later job depends on.

Artifacts are for outputs of this run that another job, another workflow or a person needs: binaries, bundles, reports. They are slower to write than a cache entry and cost storage, but they are attached to the run that made them, which is what you want for traceability.

So the verdict is a single trade. Artifacts buy correctness and an audit trail at the price of upload time and storage; merging jobs buys speed at the price of parallelism and clarity. For a two-job pipeline under 5 minutes, merge the jobs. For anything with a matrix, an approval gate or a deploy that must ship exactly what was tested, use artifacts with short retention and unique names.