How do artifacts and cache differ in GitLab CI?
IntermediateConceptGitLab CI
Answer
Artifacts are job outputs uploaded to GitLab, passed to later-stage jobs automatically (or selectively via dependencies/needs: artifacts) and downloadable from the UI; they expire (expire_in). Cache is stored by the runner (locally or in S3/GCS) to reuse dependencies between pipelines, keyed by cache:key, and is best-effort. Use cache:key:files: [package-lock.json] so the cache invalidates when the lockfile changes.
test:
cache:
key: { files: [package-lock.json] }
paths: [.npm/]
artifacts:
when: always
paths: [coverage/]
reports: { junit: junit.xml }
expire_in: 1 week
More on GitLab CI
How does GitLab CI/CD work at a high level?BeginnerWhat is a GitLab Runner and what executors exist?IntermediateWhat are the types of runners (shared, group, project) and tags?IntermediateHow do `rules:` work and how do they replace `only/except`?IntermediateWhat are workflow rules and how do they prevent duplicate pipelines?AdvancedWhat does `needs:` do and how does it create a DAG pipeline?Intermediate