Skip to content

Commit de67bd4

Browse files
committed
cancel build if there’s a queue
1 parent 22f63a9 commit de67bd4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.buildkite/build_pipeline.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ steps:
2424
- label: "Fail the build"
2525
value: ""
2626
hint: "Should we ignore checking broken links? Should we allow to run the build without failing if there's a broken link? Ignoring broken links is dangerous not just because bad links will leak into the public site but because subsequent builds and pull requests that do not fix the links fail."
27+
- wait
28+
- label: "Check for queue"
29+
if: build.source == "schedule"
30+
command: ".buildkite/scripts/check_queue.sh"
2731
concurrency: 1
2832
concurrency_group: docs-build-${BUILDKITE_BRANCH}
2933
- wait

.buildkite/scripts/check_queue.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
last_build_url="https://api.buildkite.com/v2/organizations/elastic/pipelines/${BUILDKITE_PIPELINE_SLUG}/builds?branch=${BUILDKITE_BRANCH}"
4+
cancel_build_url="https://api.buildkite.com/v2/organizations/elastic/pipelines/${BUILDKITE_PIPELINE_SLUG}/builds/${BUILDKITE_JOB_ID}/cancel"
5+
6+
LAST_BUILD_STATE=$(curl -s -H "Authorization: Bearer ${BUILDKITE_API_TOKEN}" $last_successful_build_url | jq -r '.[1].status')
7+
8+
echo "Determining if the last build is currently blocked."
9+
if [[ "$LAST_BUILD_STATE" == "blocked" ]]; then
10+
echo "The pipeline is congested. Canceling this build."
11+
curl -sX PUT -H "Authorization: Bearer ${BUILDKITE_API_TOKEN}" $cancel_build_url
12+
else
13+
echo "The pipeline is ready for a new build."
14+
fi

0 commit comments

Comments
 (0)