为什么 Google Cloud Build 在 cloudbuild.yaml 文件中没有任何配置的情况下在步骤之间传递数据

Why Google Cloud Build is passing data between steps without any configuration in cloudbuild.yaml file

参考 Google 云文档 Passing data between build steps

它说 -

Cloud Build runs your tasks as a series of build steps, which execute in isolated and containerized environments. After each step, the container is discarded. This allows you to have totally different tools and environments for each step, and by default, any data created in one step can't contaminate the next step. But sometimes you may need to persist state from one step of a build to use in subsequent steps.

现在参考下面cloudbuild.yaml来自Google Cloud Documentation example.

的代码
 
steps:
# Step 1
- name: node
  entrypoint: npm
  args: ['install']

# Step 2
- name: node
  entrypoint: npm
  args: ['test']
</pre> 

问题:为什么以及如何在我们没有步骤的情况下成功运行上述示例 在第 2 步中再次安装要求。因为按照我的想法,第 2 步应该失败(但实际上不是),因为第 1 步中完成的安装 应该被丢弃 文档。 谢谢!

这两个步骤都成功的原因是因为命令 npm install 将 download/install 您的应用程序的依赖项在 CloudBuild 运行ners 中的持久卷中,该卷在您的所有步骤之间共享然后 npm test 将 运行 针对位于同一共享卷下的应用程序代码。此卷名称是 /workspace.

仔细查看文档的这一部分,它将为您提供有关如何在步骤之间共享数据的更多详细信息:https://cloud.google.com/build/docs/configuring-builds/pass-data-between-steps#passing_data_using_workspaces