在比特桶管道中缓存剧作家浏览器二进制文件



我的目标是在Bitbucket Pipelines上为Playwright启用分片,所以我想在缓存的同时使用并行步骤。我的bitbucket-pipelines.yml脚本如下所示:

image: mcr.microsoft.com/playwright:v1.25.0-focal
definitions:
caches:
npm: $HOME/.npm
browsers: ~/.cache/ms-playwright #tried $HOME/.cache/ms-playwright ; $HOME/ms-playwright ; ~/ms-playwright
steps:
- step: &base
caches:
- npm
- node
- browsers
- step: &setup
script:
- npm ci
- npx playwright install --with-deps
- step: &landing1
<<: *base
script:
- npm run landing1
- step: &landing2
<<: *base
script:
- npm run landing2
- step: &landing3
<<: *base
script:
- npm run landing3
pipelines:
custom:
landing:
- step: *setup
- parallel:
- step: *landing1
- step: *landing2
- step: *landing3

除了尝试缓存定义的各种位置外,我还尝试将repo变量PLAYWRIGHT_BROWSERS_PATH设置为0,并希望浏览器将出现在节点模块中。

在默认位置缓存浏览器的解决方案导致了这一点(在文件注释中提到的所有4种情况下(:

虽然不单独缓存浏览器,并且将PLAYWRIGHT_BROWSERS_PATH=0与缓存节点一起使用也不起作用,但每个并行步骤都会抛出一个错误,称未安装浏览器二进制文件。

我还尝试在npm installnpm ci之间变化,用尽了这里列出的所有解决方案。

我希望有人能够专门为Bitbucket Pipelines解决这个问题,因为这是我们目前在公司使用的工具。

您不能在与需要设置的步骤不同的步骤中执行设置指令。每个步骤都在不同的代理中运行,无论是否存在任何缓存,都应该能够完成。如果存在缓存,则该步骤只应更快地运行,但结果相同!

如果您试图在缓存中耦合步骤,则会对所安装的内容失去控制:node_modules通常是一个任意的过去文件夹,不尊重运行该步骤的git-ref的package-lock.json。

此外,您的";设置";步骤不使用来自";基本";步骤定义,所以您没有正确地污染列出的";基本";缓存。不要解决这个问题,它会对你的生活造成严重破坏。

如果需要为类似的步骤重用一些设置指令,请使用另一个YAML锚点。

image: mcr.microsoft.com/playwright:v1.25.0-focal
definitions:
caches:
npm: ~/.npm
browsers: ~/.cache/ms-playwright
yaml-anchors: # nobody cares what you call this, but note anchors are not necessarily steps
- &setup-script >-
npm ci
&& npx playwright install --with-deps
# also, the "step:" prefixes are dropped by the YAML anchor
# and obviated by bitbucket-pipelines-the-application
- &base-step
caches:
- npm
# - node  # don't!
- browsers
- &landing1-step
<<: *base-step
script:
- *setup-script
- npm run landing1
- &landing2-step
<<: *base
script:
- *setup-script
- npm run landing2
- &landing3-step
<<: *base
script:
- *setup-script
- npm run landing3
pipelines:
custom:
landing:
- parallel:
- step: *landing1-step
- step: *landing2-step
- step: *landing3-step

请参阅https://stackoverflow.com/a/72144721/11715259


好处:不要使用默认的节点缓存,上传、存储和下载将被npm ci指令擦除的node_modules文件夹是在浪费时间和资源。

最新更新