Here's what I have working in Jenkins: I use an add-on called Bitbucket Status Notifier that can look for three conditions - success, failure, and cancellation of a job - and send that notification to our Teams channel (I know, Teamssss, but this is my life now):
steps {
bitbucketStatusNotify(
buildState: 'INPROGRESS',
<other attributes>)
post {
success {
bitbucketStatusNotify(
buildState: 'SUCCESSFUL',
<other attributes>)
}
failure {
bitbucketStatusNotify(
buildState: 'FAILED',
<other attributes>)
}
aborted {
bitbucketStatusNotify( buildState: 'STOPPED',
<other attributes>)
}
}In Pipelines, I can capture the exit code of successes and failures using the BITBUCKET_EXIT_CODE variable, but I can't seem to figure out how to capture it when I manually cancel a job while it's running. Here's what I have so far:
- step:
name: MyStep
script:
- <do something>
- sleep 10 (to give me a chance to find the Stop button)
- <do something else>
after-script:
- BUILD_STATUS_STRING="Notice from $BITBUCKET_REPO_FULL_NAME - Build Number $BITBUCKET_BUILD_NUMBER has ";
- |
if [ "$BITBUCKET_EXIT_CODE" == "0" ]; then
BUILD_STATUS_STRING+="succeeded";
elif [ "$BITBUCKET_EXIT_CODE" == "1" ]; then
BUILD_STATUS_STRING+="failed";
# this next condition is where it doesn't work
elif [ -z "$BITBUCKET_EXIT_CODE" ]; then
BUILD_STATUS_STRING+="been cancelled manually";
fi;
# here is where i normally curl the webhook, but let's just echo it for now
- echo $BUILD_STATUS_STRING