Artifacts


Artifacts

Transfer files between jobs using artifacts

All jobs in subsequent stages will receive the artifacts (by default)

Configuration

Name artifacts

Include and exclude paths

When to create artifacts (jobs success, failure, always)

Expire artifacts

Add untracked files

artifacts can be in default


Hands-On

Test binary in a new job and stage

  1. Create artifact from hello binary
  2. Add new stage called test
  3. Add new job in stage test
  4. Execute binary to test it

See new .gitlab-ci.yml:

git checkout origin/160_gitlab_ci/060_artifact -- '*'

Dependencies

Jobs can restrict which job artifacts to receive

Add dependencies

job_name:
  dependencies:
  - other_job
  #...

Empty list disables receiving artifacts:

job_name:
  dependencies: []
  #...

Download artifact from another pipeline

See GitLab API


Job dependencies using needs 1/

needs can start jobs from the next stage early…

job1:
  stage: stage1
  #...
job2:
  stage: stage2
  needs: job1
  #...

…or delay them in the same stage

job1:
  stage: test
  #...
job2:
  stage: test
  needs: job1
  #...

Job dependencies using needs 2/2

Depend on a job but do not consume artifacts :

job_name:
  #...

job_name2:
  needs:
    job: job_name
    artifacts: false

Consume artifacts from parent (upstream) pipeline :

job_name:
  script: cat artifact.txt
  needs:
    - pipeline: $PARENT_PIPELINE_ID
      job: create-artifact

Pro tip: When variables are enough

Passing variables between jobs is possible (since GitLab 12.9)

One job defined a dotenv artifact :

job_name:
  script: echo "FOO=bar" >build.env
  artifacts:
    reports:
      dotenv: build.env

Job in later stages automatically consume them:

job_name2:
  script: echo "${FOO}"

dependencies as well as needs limit from which jobs they are consumed