【问题标题】:BitBucket pipeline is not using cache for npm installBitBucket 管道未使用缓存进行 npm install
【发布时间】:2018-03-19 11:03:54
【问题描述】:

我有一个 BitBucket 存储库,其中包含一个名为 ui 的文件夹中的 Angular 应用程序代码和一个名为 api 的文件夹中的 Node API。

我的 BitBucket 管道为 Angular 应用运行 ng test,但未正确缓存 node_modules 文件夹。

这是我的 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

构建运行时会显示:

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

但是当它执行npm install 步骤时,它会说:

在 41.944 秒内添加了 1623 个包

我正在尝试加快构建速度,但我不知道为什么 npm 需要安装依赖项,假设它们已经包含在已恢复的缓存中。

【问题讨论】:

    标签: bitbucket bitbucket-pipelines


    【解决方案1】:

    我的猜测是,您的缓存位置不正确。 有一个预配置的节点缓存(名为“节点”),可以被激活。不需要为此做自定义缓存。(默认缓存失败,因为您的节点构建在克隆目录的子文件夹中,因此您需要自定义缓存)

    缓存位置是相对于克隆目录的。 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
    

    这可能会解决您的问题

    【讨论】:

    • 预配置的缓存是否不在 node_modules 中而不是在子文件夹中?
    • 在再次阅读文档后 (confluence.atlassian.com/bitbucket/…) 我认为您的初始方法是正确的,但您应该使用相对路径(带走前导 / 离开),因为您的克隆路径不在顶层。默认节点缓存不起作用,因为您的项目使用子文件夹。我会更新我的答案
    猜你喜欢
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 2021-02-17
    • 2017-05-28
    • 2017-09-30
    • 2019-12-29
    相关资源
    最近更新 更多