Builds download npm packages each time. Configure caching correctly in GitLab.
BeginnerScenarioGitLab CI
Answer
Situation read → Cache vs artifacts confusion.
What I'd do →
cache:
key:
files: [package-lock.json]
paths: [.npm/]
policy: pull-push
variables:
npm_config_cache: "$CI_PROJECT_DIR/.npm"
Use policy: pull in jobs that only read.
Why → Caches speed up dependencies and are best-effort; artifacts pass results between jobs.
Interview tip → Cache is not guaranteed; the build must still work without it.
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?AdvancedHow do artifacts and cache differ in GitLab CI?Intermediate