Skip to content

Instantly share code, notes, and snippets.

@raftx24
Created November 10, 2022 13:34
Show Gist options
  • Save raftx24/782e08bf0f40f47f865e83f0b43015ca to your computer and use it in GitHub Desktop.
Save raftx24/782e08bf0f40f47f865e83f0b43015ca to your computer and use it in GitHub Desktop.
stop concurrent pipelines bitbucket
#!/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