优雅地中断中间的 Google Cloud Build 步骤

Mug*_*gen 1 google-cloud-build

是否有可能以某种方式在 GCB 的某个中间步骤中优雅地退出/中断?

如果某些步骤命令以非成功代码退出,则构建流程将中断,但也将被视为失败。我想打破但保持成功的状态。

Mug*_*gen 7

我找到了一个我认为更好的解决方案:让构建使用 gcloud sdk 自行取消。

  - name: 'gcr.io/cloud-builders/gcloud'
    id: 'Cancel current build if on master'
    entrypoint: 'sh'
    args:
      - '-c'
      - |
        test $BRANCH_NAME = "master" && gcloud builds cancel $BUILD_ID > /dev/null || true
Run Code Online (Sandbox Code Playgroud)

请注意,运行构建的服务帐户 ( xxx@cloudbuild.gserviceaccount.com) 应具有取消构建的适当权限。

。