Gitlab CI - 缓存 Node.js 依赖项

时间:2021-03-24 11:22:08

标签: node.js npm gitlab-ci npm-ci

我在尝试在作业之间重用使用 npm ci 安装的软件包时遇到了重大问题。我一直在关注此文档:https://docs.gitlab.com/ee/ci/caching/#cache-nodejs-dependencies,但无论如何都会重新安装软件包:

$ npm ci --cache node_modules --prefer-offline
added 1895 packages, and audited 1896 packages in 41s

这是我的 yaml。这些文件位于名为 frontend 的文件夹中。

stages:
  - lint
  - test
  - build
  
image: node:15-alpine

# Cache modules in between jobs
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - frontend/.npm/

before_script:
  - cd frontend
  - npm ci --cache .npm --prefer-offline

do-lint:
  stage: lint
  script:
    - ./node_modules/.bin/eslint src
    - ./node_modules/.bin/stylelint "src/*.{css,scss}"

test-front-end:
  stage: test
  script:
    # Force tests to run in CI mode
    - CI=true npm test
  coverage: '/^All\sfiles.*?\s+\d+.\d+.*?\s+(\d+.\d+)/'

do-build:
  stage: build
  script:
    - npm run build

非常感谢您的帮助!

0 个答案:

没有答案