如何从不同的存储库 link cloudbuild.yaml(Google Cloud Build 触发器)

How to link cloudbuild.yaml from different repository (Google Cloud Build trigger)

基本上我想 link 我的 cloudbuild.yaml 从我的测试环境到我的开发环境。

每次提交测试环境、测试 运行 并生成报告(根据 yaml)时,我都会触发一个触发器。伟大的。

但我想在我的开发环境提交时创建一个触发器,我的测试 运行 来自我的测试存储库并创建报告。

您有 2 个解决方案。

首先,您可以下载测试项目和 运行 来自当前执行的开发构建的 Cloud Build

steps:
- name: gcr.io/cloud-builders/git
  args: ['clone', 'https://myrepo.com/testing']
- name: gcr.io/cloud-builders/gcloud
  args: ["builds", "submit"]
  dir: "testing"   # I assume that the git clone has created the testing directory

此解决方案的优点是,如果您的 Cloud Build on Test 项目失败,您会同步知道它,并且您可以在您的 Dev 当前构建中对此做出反应

对应的是测试构建过程中处理时间重复。实际上,测试构建已执行,开发测试继续(即使在待机状态下)等待测试构建结束。您还需要正确设置 Cloud Build 超时。


第二种解决方案是 API 调用以手动触发您的测试 Cloud Build 触发器。

为此,您需要自定义以下步骤:

  • 测试项目ID
  • 触发器UUID。当您点击您的触发器进行编辑时,您可以在页面 URL 中找到它。

如果需要,您也可以更改 branchName

steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    entrypoint: 'bash'
    args:
      - '-c'
      - |
             curl -d '{"branchName":"master"}' -X POST -H "Content-type: application/json" -H "Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" https://cloudbuild.googleapis.com/v1/projects/<PROJECT_TEST_ID>/triggers/<TRIGGER_UUID>:run

在这里,您无需等待构建结束,您可以节省 Cloud Build 持续时间(和资金),但在构建失败的情况下您无法做出反应。