How to Pass Artifacts Between Jobs in GitLab CI/CD
A job uploads files as artifacts and later-stage jobs download them automatically before they run.
Declare artifacts:paths in the producing job. Jobs in later stages receive those artifacts by default; narrow the set with dependencies:.
Steps
- Add
artifacts:pathsto the producing job listing the output files. - Place the consumer in a later stage so it runs after the producer.
- Use
dependencies:to restrict which jobs' artifacts are pulled in.
Pipeline
.gitlab-ci.yml
stages: [build, deploy]
build:
stage: build
script: npm run build
artifacts:
paths:
- dist/
expire_in: 1 hour
deploy:
stage: deploy
dependencies:
- build
script: ./deploy.sh dist/Gotchas
- Set
expire_inso artifacts do not pile up and consume storage. - An empty
dependencies: []downloads no artifacts at all, which is handy for jobs that need none.
Related guides
How to Cache Dependencies in GitLab CI/CDSpeed up GitLab CI/CD by caching package directories with a cache key tied to the lockfile via cache:key:file…
How to Build a DAG Pipeline With needs in GitLab CI/CDRun GitLab CI/CD jobs out of stage order with needs, letting a job start as soon as its specific dependencies…