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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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

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
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

2,570 views 1 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you