我有一个 BitBucket 存储库,其中包含名为 ui
的文件夹中的 Angular 应用程序代码。以及名为 api
的文件夹中的 Node API .
我的 BitBucket 管道运行 ng test
对于 Angular 应用程序,但 node_modules
文件夹未正确缓存。
这是我的 BitBucket 管道 yml 文件:
image: trion/ng-cli-karma
pipelines:
default:
- step:
caches:
- angular-node
script:
- cd ui
- npm install
- ng test --watch=false
definitions:
caches:
angular-node: /ui/node_modules
当构建运行时,它显示:
Cache "angular-node": Downloading
Cache "angular-node": Extracting
Cache "angular-node": Extracted
但是当它执行
npm install
时步骤它说:added 1623 packages in 41.944s
我正在尝试加快构建速度,但我无法弄清楚为什么 npm 需要安装依赖项,假设它们已经包含在已恢复的缓存中。
最佳答案
我的猜测是,您的缓存位置不正确。有一个可以激活的预配置节点缓存(名为“节点”)。无需为此做自定义缓存。 (默认缓存失败,因为你的node build是在clone目录下的子文件夹,所以需要自定义缓存)
缓存位置相对于克隆目录。 bitbucket 克隆到 /opt/atlassian/pipelines/agent/build
这可能就是您的绝对缓存路径不起作用的原因。
简单地使缓存引用相对应该可以解决问题
pipelines:
default:
- step:
caches:
- angular-node
script:
- cd ui
- npm install
- ng test --watch=false
definitions:
caches:
angular-node: ui/node_modules
这可能会解决您的问题
关于BitBucket 管道未使用缓存进行 npm 安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49361433/