Managing Artifacts in GitLab CI Pipelines

Configure GitLab CI artifacts for test reports, build outputs, and cross-job file sharing. Covers paths, expire_in, reports, and when conditions.

Caching & Artifacts

Detailed Explanation

Managing Artifacts in GitLab CI

Artifacts are files created by a job and stored on the GitLab server. They can be downloaded, browsed in the GitLab UI, and passed to downstream jobs.

Basic Artifact Configuration

build:
  script: npm run build
  artifacts:
    paths:
      - dist/
      - build/
    expire_in: 1 week

Test Reports

test:
  script: pytest --junitxml=report.xml
  artifacts:
    reports:
      junit: report.xml
      coverage_report:
        coverage_format: cobertura
        path: coverage.xml

JUnit reports appear in merge requests. Cobertura coverage reports show line-by-line coverage diffs.

Conditional Artifacts

test:
  script: npm test
  artifacts:
    paths:
      - test-results/
    when: always
    expire_in: 7 days

The when: always ensures artifacts are uploaded even if the job fails. This is critical for test reports and logs.

Artifact Dependencies

build:
  stage: build
  script: make build
  artifacts:
    paths:
      - dist/

deploy:
  stage: deploy
  needs:
    - job: build
      artifacts: true
  script: make deploy

The needs keyword with artifacts: true ensures the deploy job receives the build artifacts. Without needs, all artifacts from the previous stage are downloaded by default.

Exclude Patterns

build:
  artifacts:
    paths:
      - build/
    exclude:
      - build/**/*.map
      - build/**/*.test.js

Size Limits

GitLab imposes artifact size limits per project (default 100MB on GitLab.com). For large artifacts, consider uploading to external storage (S3, GCS) from your script instead.

Use Case

Use artifacts whenever you need to pass build outputs between jobs, store test reports for merge request visibility, or preserve debug logs from failing pipelines.

Try It — GitLab CI Config Generator

Open full tool