From ec8e6c40b91593592daa0d7f883b098080d3343f Mon Sep 17 00:00:00 2001 From: lidongyang Date: Mon, 20 Jul 2026 15:46:59 +0800 Subject: [PATCH] [fix](ci) cancel superseded buildall revisions --- .../workflows/comment-to-trigger-teamcity.yml | 3 +++ .../pipeline/common/teamcity-utils.sh | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.github/workflows/comment-to-trigger-teamcity.yml b/.github/workflows/comment-to-trigger-teamcity.yml index 6227490e559302..0f5181532d7544 100644 --- a/.github/workflows/comment-to-trigger-teamcity.yml +++ b/.github/workflows/comment-to-trigger-teamcity.yml @@ -316,6 +316,9 @@ jobs: else changed="false" fi + if [[ "${{ steps.parse.outputs.COMMENT_TRIGGER_TYPE }}" == "buildall" ]]; then + cancel_builds_of_pr "${{ steps.parse.outputs.PULL_REQUEST_NUM }}" + fi trigger_or_skip_build \ "${changed}" \ "${{ steps.parse.outputs.PULL_REQUEST_NUM }}" \ diff --git a/regression-test/pipeline/common/teamcity-utils.sh b/regression-test/pipeline/common/teamcity-utils.sh index c9b61c6fb548b2..2d6ff854cea766 100644 --- a/regression-test/pipeline/common/teamcity-utils.sh +++ b/regression-test/pipeline/common/teamcity-utils.sh @@ -215,6 +215,33 @@ cancel_queue_build() { } # cancel_queue_build "$1" "$2" +cancel_builds_of_pr() { + local PULL_REQUEST_NUM="${PULL_REQUEST_NUM:-$1}" + if [[ -z "${PULL_REQUEST_NUM}" ]]; then + echo "Usage: cancel_builds_of_pr PULL_REQUEST_NUM" && return 1 + fi + + local builds + builds=$( + curl -s -u OneMoreChance:OneMoreChance -H "Accept: application/json" \ + "http://43.132.222.7:8111/app/rest/builds?locator=branch:pull/${PULL_REQUEST_NUM},running:true" | + jq -r '.build[] | "builds/id:\(.id)"' + curl -s -u OneMoreChance:OneMoreChance -H "Accept: application/json" \ + "http://43.132.222.7:8111/app/rest/buildQueue" | + jq -r ".build[] | select(.branchName == \"pull/${PULL_REQUEST_NUM}\") | \"buildQueue/id:\(.id)\"" + ) || return 1 + + local build + for build in ${builds}; do + curl -s -X POST \ + -u OneMoreChance:OneMoreChance \ + -H "Content-Type:application/json" \ + "http://43.132.222.7:8111/app/rest/${build}" \ + -d '{ "comment": "Canceling this build before triggering a new buildall", "readdIntoQueue": false }' || return 1 + echo "INFO: canceled ${build} for PR ${PULL_REQUEST_NUM}" + done +} + skip_build() { # 对于不需要跑teamcity pipeline的PR,直接调用github的接口返回成功 if [[ -z "${GITHUB_TOKEN}" ]]; then