File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 33last_build_url=" https://api.buildkite.com/v2/organizations/elastic/pipelines/${BUILDKITE_PIPELINE_SLUG} /builds?branch=${BUILDKITE_BRANCH} "
44cancel_build_url=" https://api.buildkite.com/v2/organizations/elastic/pipelines/${BUILDKITE_PIPELINE_SLUG} /builds/${BUILDKITE_JOB_ID} /cancel"
55
6- LAST_BUILD_STATE=$( curl -s -H " Authorization: Bearer ${BUILDKITE_API_TOKEN} " $last_successful_build_url | jq -r ' .[1].status' )
6+ # Don't look at this build (it's running now!)
7+ # Don't look at the last build (it's okay if it's still running!)
8+ # Look three builds back instead (if this build is still running,
9+ # it means there's already one in the queue and we can safely cancel this one)
10+ THIRD_TO_LAST_BUILD_STATE=$( curl -s -H " Authorization: Bearer ${BUILDKITE_API_TOKEN} " $last_successful_build_url | jq -r ' .[2].status' )
711
8- echo " Determining if the last build is currently blocked ."
9- if [[ " $LAST_BUILD_STATE " == " blocked " ]]; then
12+ echo " Determining if there are multiple builds waiting ."
13+ if [[ " $THIRD_TO_LAST_BUILD_STATE " == " running " ]]; then
1014 echo " The pipeline is congested. Canceling this build."
1115 curl -sX PUT -H " Authorization: Bearer ${BUILDKITE_API_TOKEN} " $cancel_build_url
1216else
You can’t perform that action at this time.
0 commit comments