Gitlab CI:npm不喜欢缓存的node_modules

问题描述 投票:0回答:2

互联网上充斥着关于Gitlab没有缓存的抱怨,但在我的情况下,我认为,Gitlab CI确实可以正确缓存。问题是,无论如何,npm似乎再安装所有东西。

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - vendor/
    - bootstrap/
    - node_modules/

build-dependencies:
  image: ...
  stage: build
  script:
  - cp .env.gitlab-testing .env
  - composer install --no-progress --no-interaction
  - php artisan key:generate
  - npm install
  - npm run prod
  - npm run prod
  artifacts:
    paths:
    - vendor/
    - bootstrap/
    - node_modules/
    - .env
    - public/mix-manifest.json
  tags:
  - docker

这是我的gitlab-ci.yml文件(嗯......相关部分)。虽然使用了缓存的composer依赖项,但node_modules却没有。我甚至在绝望中添加了缓存和工件的所有内容。

npm gitlab npm-install gitlab-ci
2个回答
1
投票

实际上它应该工作,你的缓存是全局设置,你的密钥是指当前分支${CI_COMMIT_REF_SLUG} ...

这是我的构建,似乎在各阶段之间缓存node_modules。

image: node:latest

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
  - node_modules/
  - .next/

stages:
  - install
  - test
  - build
  - deploy

install_dependencies:
  stage: install
  script:
    - npm install

test:
  stage: test
  script:
    - npm run test

build:
  stage: build
  script:
    - npm run build


0
投票

默认缓存路径为~/.npm

要设置npm缓存目录:

npm config set cache <path> --global

有关更多信息,请参阅here

© www.soinside.com 2019 - 2024. All rights reserved.