Job Artifacts
You'll learn how to configure GitLab CI/CD job artifacts to preserve important files between pipeline stages, control their lifespan, and manage storage efficiently.
What Are Job Artifacts?
Job artifacts are files or directories that your CI/CD job produces and preserves after the job completes. Think of artifacts like boxed leftovers from a meal—they're the valuable output you want to keep and potentially use later, rather than throwing everything away when the kitchen closes.
Configuring Artifacts
In your .gitlab-ci.yml, use the artifacts: keyword to specify what to preserve:
build-job:
script:
- echo "Building application..."
- mkdir build
- echo "app-v1.0" > build/app.jar
artifacts:
paths:
- build/
This saves the entire build/ directory for downstream jobs or download.
Artifact Expiration
By default, artifacts live forever (consuming storage). Set expiration to auto-clean:
test-job:
script:
- ./run-tests.sh > test-results.txt
artifacts:
paths:
- test-results.txt
expire_in: 1 week
Common values: 30 mins, 2 hrs, 1 day, 1 week, never.
Managing Storage
- Be selective: Only preserve what's necessary (compiled binaries, test reports, deployment packages)
- Set appropriate expiration: Short-lived artifacts for temporary debug files, longer for releases
- Use
when:to control artifact capture (on_success,on_failure,always)
artifacts:
when: on_failure
paths:
- logs/
Key Takeaway: Job artifacts preserve specific files after job completion, enabling cross-job data sharing while expiration policies prevent storage bloat—configure paths, expiration, and conditions to balance utility and cost.