Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I capture it when a Bitbucket Pipeline is manually stopped?

inger_klekacz February 1, 2021

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

 

1 answer

1 accepted

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 2, 2021

Hi @inger_klekacz ,

I'm not sure about the value of $BITBUCKET_EXIT_CODE when a build is manually stopped. However, the after-script runs only when a step succeeds or fails. If the build is stopped, the after-script won't run, which basically doesn't make possible to capture this use case there.

That would be dependant on the implementation of https://jira.atlassian.com/browse/BCLOUD-19866. If you'd be interested in this, I would suggest to add your vote in the feature request (by selecting the Vote for this issue link) as the number of votes helps the development team and product managers better understand the demand for new features. You are more than welcome to leave any feedback, and you can also add yourself as a watcher (by selecting the Start watching this issue link) if you'd like to get notified via email on updates.

Implementation of new features is done as per our policy here https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html and any updates will be posted in the feature request.

Please feel free to let me know if you have any questions.

Kind regards,
Theodora

inger_klekacz February 2, 2021

Thanks for this information! I've upvoted and commented upon the request.

Like Theodora Boudale likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events