Skip to content
Latchkey

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:paths to 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_in so 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

Run this faster and cheaper on Latchkey managed runners. Start free →