Job Artifacts: Passing Data Between Jobs
What you'll learn: How to preserve files generated by one job and make them available to downstream jobs in your GitLab pipeline.
What Are Job Artifacts?
By default, each GitLab job runs in isolation—when a job finishes, everything it created disappears. Artifacts are files or directories you explicitly tell GitLab to save after a job completes. Think of artifacts as a handoff baton in a relay race: one runner finishes their leg, passes the baton (artifact) to the next runner, who can then continue from there.
Why Artifacts Matter
Without artifacts, you'd need to rebuild everything from scratch in every job. If your build job compiles code into binaries, your test job needs those same binaries—not to rebuild them again. Artifacts let you build once and reuse the output across multiple stages.
Defining Artifacts in .gitlab-ci.yml
You specify artifacts using the artifacts keyword with a paths list:
build-job:
stage: build
script:
- echo "Compiling application..."
- mkdir build
- echo "binary-v1.0" > build/app.bin
artifacts:
paths:
- build/
test-job:
stage: test
script:
- ls build/ # The build/ directory is automatically available
- cat build/app.bin
The build-job saves the build/ directory. GitLab automatically downloads artifacts from previous stages, so test-job can immediately access build/app.bin without recreating it.
Key Takeaway:
Artifacts preserve job outputs and automatically pass them to later pipeline stages, enabling efficient data sharing without rebuilding from scratch.