Created
November 10, 2022 13:34
-
-
Save raftx24/782e08bf0f40f47f865e83f0b43015ca to your computer and use it in GitHub Desktop.
stop concurrent pipelines bitbucket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function callBitbucket { | |
curl --location --request $1 -g \ | |
--header 'Accept: application/json' \ | |
-u ${BITBUCKET_USER}:${BITBUCKET_PASSWORD} \ | |
"https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/$2" | |
} | |
export -f callBitbucket; | |
#we should not stop most recent runner! | |
callBitbucket GET "pipelines/?target.branch=$BITBUCKET_BRANCH&sort=-created_on&=PENDING&status=BUILDING&status=IN_PROGRESS&trigger_type=PUSH" \ | |
| jq '.values[].uuid' \ | |
| xargs -I% echo 'pipelines/%/stopPipeline' \ | |
| tail -n +2 \ | |
| xargs -I {} bash -c 'callBitbucket POST {};' | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment