gpt4 book ai didi

google-cloud-build - 如何防止云构建并行运行构建?

转载 作者:行者123 更新时间:2023-12-02 11:20:52 25 4
gpt4 key购买 nike

我们正在使用云构建在 GCP 上进行持续部署。当快速提交提交时(例如在开发中),触发的构建并行运行。有时那些相互干扰。例如,当两个应用引擎部署同时运行时。

有没有一种方法或最佳实践可以强制从同一个构建触发器触发的构建一个接一个地运行?

问候,
卡斯腾

最佳答案

我通过在我的 cloudbuild.yaml 上添加一个初始步骤来做到这一点。文件。它的作用是:

  • 通过 gcloud builds list --ongoing --format='value(id)' --filter="substitutions.TRIGGER_NAME=$TRIGGER_NAME" 获取所有正在进行的构建 ID .
  • 遍历它但跳过第一个,列表按最新创建时间排序,因此它不会停止作为第一个索引的最新构建
  • 运行 gcloud builds cancel ${on_going_build[i]}取消构建

  • 请查看 cloudbuild.yaml以下
    steps:
    - id: "Stop Other Ongoing Build"
    name: 'gcr.io/cloud-builders/gcloud'
    entrypoint: 'bash'
    args:
    - -c
    - |
    on_going_build=($(gcloud builds list --ongoing --format='value(id)' --filter="substitutions.TRIGGER_NAME=$TRIGGER_NAME" | xargs))
    for (( i=0; i<${#on_going_build[@]}; i++ )); do
    if [ "$i" -gt "0" ]; then # skip current
    echo "Cancelling build ${on_going_build[i]}"

    gcloud builds cancel ${on_going_build[i]}
    fi
    done

    关于google-cloud-build - 如何防止云构建并行运行构建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55905120/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com