Skip to main content

Artifact

A CI/CD artifact is a file or image reference produced by one pipeline job and passed to later jobs or stored for download, such as binaries, test reports, or an image tag.

Understanding CI/CD Artifacts

What Is a CI/CD Artifact

An artifact is the output of a pipeline job that something else needs. A build job produces a compiled binary or a container image, a test job produces a JUnit report, and a scan job produces a SARIF file. Because every job starts on a clean runner, anything not saved as an artifact (or pushed to a registry) is lost when the job ends.

The key discipline is to build once and promote the same artifact through every environment, so what you tested is exactly what you ship.

Artifact vs Cache vs Registry

Concept Purpose
Artifact Pass outputs between jobs or keep them for download
Cache Speed up repeated work such as dependency downloads
Registry Long-term storage for container images and packages

Caches are an optimisation and can be missing at any time. Artifacts are a contract between jobs. Container images belong in a registry, and the artifact you pass along is just the tag or digest.

Passing an Artifact Between Jobs

flowchart LR A[Build job] -->|image digest| B[Test job] B -->|junit.xml| C[Report upload] B -->|same digest| D[Deploy job] classDef job fill:#326CE5,color:#FFFFFF classDef out fill:#F97316,color:#FFFFFF class A,B,D job class C out
YAML
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm test -- --coverage
- uses: actions/upload-artifact@v4
if: always() # keep reports even when tests fail
with:
name: coverage-report
path: coverage/
retention-days: 14
coverage-gate:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: coverage-report
path: coverage/
- run: jq '.total.lines.pct' coverage/coverage-summary.json

Handy Commands

Bash
# GitHub: download an artifact from a run
gh run download 1234567890 --name coverage-report
# GitHub: list artifacts for a run
gh api repos/zerodha/kite-api/actions/runs/1234567890/artifacts
# GitLab: download all artifacts of a job
glab ci artifact main build-image

Troubleshooting

Symptom Check What to Look For
Artifact not found downstream Upload and download names Names must match exactly
Upload very slow or huge Path glob Upload only the files you need
Storage quota filling Retention settings Set retention-days on every upload
Tip

Use if: always() when uploading test results. Reports matter most when tests fail, and upload steps are skipped after a failure by default.

Remember

Tag images with the Git commit SHA and reference them by digest. Mutable tags such as latest make it impossible to know what is really running.

Security

Artifacts can contain secrets, debug logs, and database dumps. Keep retention short and check who can download artifacts, especially on public repositories.

Common Mistake

Storing Docker images as pipeline artifacts. Push images to a registry such as ECR or GitLab Registry and pass only the tag or digest between jobs.

Frequently Asked Questions

Why pass artifacts between jobs instead of rebuilding in each stage?

Rebuilding can pull different dependency versions or hit environment differences, so the thing you tested is not the thing you deploy. Passing one built artifact guarantees the tested output is identical to what ships.

What is the difference between an artifact and a cache in CI?

A cache speeds up repeated downloads and may be missing at any time. An artifact is a guaranteed output handed from one job to another or kept for later download, so pipelines may depend on it.

How long should CI artifacts be kept?

Keep build outputs and reports only as long as you need them, commonly 7 to 30 days. Long retention increases storage cost and the window in which leaked data can be downloaded.

Found a mistake, an outdated step or a broken link?