Monk CIMonk CI home

3 Dec, 2026Himanshu Sharma

GitHub Actions Artifacts: Upload and Download


Use GitHub Actions artifacts to pass build outputs between jobs, keep diagnostic files, and fix missing downloads with explicit names, paths and dependencies.

GitHub Actions artifacts preserve files produced by a job and let later jobs download them. Upload the intended output, give it a clear name, and make the consuming job depend on the producing job before downloading that same name.

Use an artifact for a build output or report you need to inspect or pass onward. Use a dependency cache for reusable data that can be missing without preventing a correct build.

How do you pass a file between two jobs?

Upload the file in the producer and download it in a job with needs pointing to that producer. The jobs have separate workspaces; a file on one runner does not appear on another automatically.

This complete GitHub.com example creates and checks a small payload. It needs no repository checkout or application-specific build script:

name: Artifact handoff example
on: workflow_dispatch
permissions:
  contents: read
jobs:
  produce:
    runs-on: monkci-ubuntu-latest
    steps:
      - name: Create an output
        run: |
          mkdir -p output
          printf '%s\n' 'artifact-handoff-ok' > output/result.txt
      - name: Upload output
        uses: actions/upload-artifact@v7
        with:
          name: build-output
          path: output/result.txt
          if-no-files-found: error
          retention-days: 7
  consume:
    needs: produce
    runs-on: monkci-ubuntu-latest
    steps:
      - name: Download output
        uses: actions/download-artifact@v8
        with:
          name: build-output
          path: received
      - name: Verify the output
        run: |
          test -f received/result.txt
          test "$(cat received/result.txt)" = 'artifact-handoff-ok'

Seven days is an illustrative retention choice, not a recommendation for every repository. Respect repository and organization policy. These action versions are for GitHub.com and are not supported on GitHub Enterprise Server; use the versions documented for your GHES installation. Check runner requirements when maintaining self-hosted machines.

The upload action and download action document their inputs and compatibility. Major-version tags keep the example readable; pin reviewed action commits in workflows where your dependency policy requires immutable references.

Diagram for GitHub Actions Artifacts: Upload and Download
Diagram for GitHub Actions Artifacts: Upload and Download

What should the name and path represent?

The name identifies the stored artifact; the path selects local files on upload or a local destination on download. Keeping those concepts separate prevents many “artifact not found” and “file not found” errors.

FieldIn this exampleMeaning
Upload namebuild-outputStored artifact to request later
Upload pathoutput/result.txtExisting file on the producer
Download namebuild-outputArtifact to retrieve
Download pathreceivedDirectory created on the consumer
needsproduceWait for the producing job to succeed

For matrix jobs, give each producer a distinct name containing the relevant matrix value. Do not have several jobs append files to one artifact name. If you later combine downloads, avoid overwriting equal filenames from different producers.

How should you retain reports when tests fail?

Place the report upload after the test step and use an appropriate status condition, such as if: always(), when diagnostic files should survive a failed test. Do not hide the original test exit code just to reach the upload step.

Choose missing-file behavior deliberately. A required release bundle should fail when absent. A diagnostic report that the test process might never create can use warning behavior, with that absence visible in the logs. Retaining output does not convert a failed test into a successful build.

Why can a download succeed but my script fail?

The download and the application's expectations are separate checks. Inspect the resulting directory before changing the build.

  1. Confirm the artifact name and the workflow run being accessed.
  2. Check whether the producer really uploaded files, rather than matching an empty path.
  3. Inspect the downloaded directory structure and use that path in subsequent steps.
  4. Check execution permissions if the result is a program or shell script.
  5. Validate expected content or checksums before deployment.

For permissions that must survive transfer, package the files in a tar archive and extract it deliberately after download. Avoid uploading an entire workspace: it can include credentials, generated configuration and irrelevant dependencies.

How are artifacts different from caches?

An artifact is an explicit output of a particular run. A cache is an optional optimization for recreating outputs more cheaply. Design the workflow to complete correctly without a cache, while treating a missing required artifact as an error.

Use the Actions cache guide for dependency reuse. When splitting tests, the parallel test guide explains distinct work assignments; report artifacts should preserve each shard's identity.

Changing to Monk CI runners changes where a job executes. It does not make files automatically shared between jobs; keep explicit transfers when following the runner migration guide.

Frequently asked questions

Can I download an artifact from another workflow run?

Yes, but the simple same-run example is not sufficient. You need the appropriate run or repository identifiers and a token with access to that artifact. Follow the download action's cross-run instructions and treat artifacts from untrusted runs as untrusted input, especially before executing their contents.

Does needs copy the producer's workspace?

No. It establishes a job dependency and exposes supported job outputs; it does not transfer files or share a local filesystem. Upload files explicitly and download them in the dependent job. This remains important when both jobs happen to use the same runner label or provider.

Should I upload node_modules as a build artifact?

Only if that directory is intentionally part of the deployable output and compatible with its destination. For ordinary dependency installation, cache the package manager's reusable downloads instead. Avoid turning a large platform-specific dependency tree into an accidental deployment contract between otherwise independent jobs.

Can I keep artifact files indefinitely?

Retention is governed by the artifact action and repository or organization policy. Choose a period that matches the output's purpose and use appropriate release or storage systems for long-term distribution. This example's seven-day setting is simply a demonstration of an explicit retention choice.

Try Monk CI for free

Continue with GitHub