简体   繁体   English

BitBucket管道未将缓存用于npm安装

[英]BitBucket pipeline is not using cache for npm install

I have a single BitBucket repository containing the code for an Angular app in a folder called ui and a Node API in a folder called api . 我有一个BitBucket存储库,其中包含ui文件夹中的Angular应用程序代码和api文件夹中的Node API。

My BitBucket pipeline runs ng test for the Angular app, but the node_modules folder isn't being cached correctly. 我的BitBucket管道为Angular应用程序运行ng test ,但是node_modules文件夹未正确缓存。

This is my BitBucket Pipeline yml file: 这是我的BitBucket Pipeline 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

When the builds runs it shows: 构建运行时,它显示:

Cache "angular-node": Downloading
Cache "angular-node": Extracting
Cache "angular-node": Extracted

But when it performs the npm install step it says: 但是,当执行npm install步骤时,它会说:

added 1623 packages in 41.944s 在41.944时增加了1623个程序包

I am trying to speed the build up and I can't work out why npm needs to install the dependencies assuming they are already contained in the cache which has been restored. 我试图加快构建速度,但我想不出为什么npm需要安装依赖项,前提是它们已经包含在已还原的缓存中。

my guess is, your cache position is not correct. 我的猜测是,您的缓存位置不正确。 there is a pre-configured node cache (named "node") that can just be activated. 有一个预配置的节点缓存(名为“节点”)可以被激活。 no need to do a custom cache for that. 无需为此做自定义缓存。 (the default cache fails, because your node build is in a sub folder of the clone directory, so you need a custom cache) (默认缓存失败,因为您的节点版本位于克隆目录的子文件夹中,因此您需要自定义缓存)

cache positons are relative to the clone directory. 缓存位置相对于克隆目录。 bitbucket clones into /opt/atlassian/pipelines/agent/build thats probably why your absolute cache-path did not work. bitbucket克隆到/opt/atlassian/pipelines/agent/build这可能就是您的绝对缓存路径不起作用的原因。

simply making the cache reference relative should do the trick 只需使缓存引用相对应即可

pipelines:
  default:
    - step:
        caches:
        - angular-node
        script:
        - cd ui
        - npm install
        - ng test --watch=false
definitions:
  caches:
    angular-node: ui/node_modules

that may fix your issue 可能会解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM