Use cache for dependencies and artifacts for outputs.

Section: Speed and portability

GitLab cache vs artifacts

yaml
yaml
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm/

artifacts:
  paths:
    - dist/
  expire_in: 1 week
Explanation

Cache is for speeding up repeated work; artifacts are for preserving job outputs.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Speed and portability
Cache npm dependencies in GitHub Actions
Reuse package manager downloads between runs.
OpenIn sheetyamlsame section
Upload build artifacts
Publish files from one job for later download or deploy.
OpenIn sheetyamlsame section
GitLab matrix variables
Expand one logical job into multiple combinations.
OpenIn sheetyaml1 tag match
GitHub Actions test matrix
Run the same job across multiple Node versions.
GitHub reusable workflow
Call a shared workflow from another repository or workflow file.