Skip to content

Lesson 3 of 9 · 22m

Artifacts and Data Flow: What Should Move Between Jobs

Artifacts as pipeline outputs, expiry as a design decision, and the data-flow patterns that keep distributed jobs correct.

A CI pipeline is a distributed system with terrible messaging: jobs cannot talk to each other except through artifacts, cache, variables, and external services. Most flaky pipelines are really data-flow bugs. Something was supposed to move from one job to another and did not, or something old was mistaken for something new.

Artifacts are versioned handoffs

Artifacts belong to a pipeline. They are the correct way to pass build outputs, test reports, generated files, and release metadata.

build:
  script:
    - npm ci
    - npm run build
  artifacts:
    paths:
      - dist/
      - build-info.json
    expire_in: 1 week

deploy-preview:
  needs: [build]
  script:
    - test -d dist
    - ./scripts/deploy-preview dist

The downstream job should validate assumptions instead of blindly trusting the handoff. If dist must exist, check it. If the metadata must include a commit SHA, verify it. A clear early failure is cheaper than deploying an empty directory.

expiry is part of the contract

Artifacts consume storage forever unless you expire them. Test reports often need only days; release artifacts may need months. Do not use one global value because it is easy. Storage bills and retention requirements disagree.

performance-report:
  artifacts:
    reports:
      performance: performance.json
    expire_in: 30 days

Report artifacts have a second job: GitLab parses some of them into merge request widgets. That is user interface data, not just files in object storage.

Variables are not a file transfer mechanism

Small scalar values are fine in dotenv artifacts. Large structured data belongs in files. Secrets do not belong in artifacts at all.

metadata:
  script:
    - printf 'APP_VERSION=%s
' "$CI_COMMIT_SHA" > build.env
  artifacts:
    reports:
      dotenv: build.env

Downstream jobs can read APP_VERSION as a variable. This is useful, but remember variables are strings. They do not preserve arrays, file permissions, binary data, or nuance.

Debugging data-flow failures

When a downstream job fails, inspect upstream first: did the artifact exist, was it expired, did needs pull the artifact you expected, did a path overwrite another file? The job graph tells you ordering. It does not prove data correctness.

Field notes

  • Artifacts pass outputs inside a pipeline; cache accelerates dependencies across pipelines.
  • Validate artifact contents in the consuming job before deploying or publishing.
  • Use expire_in intentionally; indefinite retention becomes a storage incident.
  • Do not store private keys, tokens, or production database dumps in artifacts.
  • needs without artifact validation gives you ordering, not correctness.

Was this lesson helpful?

Sign in to rate