Cache — dependency caching. Artifacts — file transfer between jobs.
Cache:
1cache:2 key:3 files:4 - package-lock.json5 paths:6 - node_modules/7 policy: pull-push89# Read only10cache:11 key: ${CI_COMMIT_REF_SLUG}12 paths:13 - node_modules/14 policy: pull
Artifacts:
1build:2 stage: build3 script:4 - npm ci && npm run build5 artifacts:6 paths:7 - dist/8 expire_in: 1 week9 when: on_success1011deploy:12 stage: deploy13 dependencies:14 - build15 script:16 - aws s3 sync dist/ s3://my-bucket/1718# Tests with reports19test:20 script:21 - npm test -- --coverage22 artifacts:23 reports:24 junit: test-results.xml25 coverage_report:26 coverage_format: cobertura27 path: coverage/cobertura.xml28 when: always
Cache vs Artifacts: Cache for dependencies (may be stale), Artifacts for build output (guaranteed).