File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 1
1
steps :
2
+ - key : " cancel-existing-builds"
3
+ command : " .buildkite/scripts/cancel_running_pr.sh || true"
2
4
- key : " build-pr-setup"
3
5
label : " setup"
4
6
command : " .buildkite/scripts/build_pr_commit_status.sh pending"
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ export BUILD_PR_MACHINE_TYPE="n2-standard-4"
28
28
# https://buildkite.com/docs/pipelines/managing-log-output#redacted-environment-variables
29
29
if [[ " $BUILDKITE_PIPELINE_SLUG " == " docs-build-pr" ]]; then
30
30
export GITHUB_TOKEN=$( retry 5 vault kv get -field=value secret/ci/elastic-docs/docs_preview_cleaner)
31
-
31
+ export BUILDKITE_API_TOKEN= $( retry 5 vault kv get -field=value secret/ci/elastic-docs/buildkite_token )
32
32
if [[ ${GITHUB_PR_BASE_REPO:= " unset" } == " docs" ]]; then
33
33
# Docs PR require a full rebuild - so let's boost the builds so they don't take 2 hours
34
34
export BUILD_PR_MACHINE_TYPE=" n2-highcpu-32"
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ set -euo pipefail
3
+ set +x
4
+
5
+ # This script should only be invoked by the Buildkite PR bot
6
+ if [ -z ${GITHUB_PR_NUMBER+set} ] || [ -z ${GITHUB_PR_BASE_REPO+set} ]; then
7
+ echo " One of the following env. variable GITHUB_PR_NUMBER, GITHUB_PR_BASE_REPO is missing - exiting."
8
+ exit 1
9
+ fi
10
+
11
+ running_builds_url=" https://api.buildkite.com/v2/organizations/elastic/pipelines/${BUILDKITE_PIPELINE_SLUG} /builds"
12
+ running_builds_url+=" ?branch=${BUILDKITE_BRANCH} &state[]=scheduled&state[]=running"
13
+ jq_filter=" map(select(any(.meta_data; .repo_pr == \" ${GITHUB_PR_BASE_REPO} _${GITHUB_PR_NUMBER} \" ))) | .[] .number"
14
+
15
+ for bn in $( curl -sH " Authorization: Bearer ${BUILDKITE_API_TOKEN} " $running_builds_url | jq -c " ${jq_filter} " ) ; do
16
+ if [ " $bn " != " ${BUILDKITE_BUILD_NUMBER} " ]; then
17
+ echo " Cancelling build ${bn} targetting the same PR"
18
+ cancel_url=" https://api.buildkite.com/v2/organizations/elastic/pipelines/${BUILDKITE_PIPELINE_SLUG} /builds/${bn} /cancel"
19
+ curl --silent -X PUT -H " Authorization: Bearer ${BUILDKITE_API_TOKEN} " " ${cancel_url} " > /dev/null
20
+ fi
21
+ done
22
+
23
+
You can’t perform that action at this time.
0 commit comments