NPM CI 在同一个 Jenkins 管道上花费不同的时间

NPM CI takes different amount of time on the same Jenkins Pipeline

我在 Jenkins 上有一个管道 运行,它在 运行 我的 lint、单元和集成测试之前执行了几个步骤。这些步骤之一是安装依赖项。这是使用 npm ci 完成的。

我试图弄清楚是什么导致此步骤花费不同的时间,有时大约 15 秒,有时超过 1 分钟。不幸的是,很难在网上找到任何可以解释这种随机行为的内容。

管道 运行 在同一代码库上,因此没有对依赖项进行任何更改。

如果有人可以解释造成这种差异的原因,或者向我指出可能有帮助的资源,那将非常有帮助。

这种预期行为与您不应期望的时间总是相同。

安装节点模块时有很多因素,例如

  • NPM 注册服务器可能很忙意味着更多的负载,所以您可以预期延迟
  • 您的本地服务器统计信息,例如,如果您的 jenkins CPU 是 100%,那么我可以期待恒定的安装时间吗?
  • 网络流量等

所以你不应该依赖于注册表总是在相同的时间回复你。

您可以通过添加和删除节点模块轻松重现。

如果您讨厌延迟,您可以配置自己的 NPM registry

Verdaccio is a simple, zero-config-required local private npm registry. No need for an entire database just to get started! Verdaccio comes out of the box with its own tiny database, and the ability to proxy other registries (eg. npmjs.org), caching the downloaded modules along the way. For those looking to extend their storage capabilities, Verdaccio supports various community-made plugins to hook into services such as Amazon's s3, Google Cloud Storage or create your own