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

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 to manually fail a bitbucket pipeline in bash script


function run_cmd()
eval $cmd

if [[ $? -eq 0 ]]; then
echo "Failed to execute $cmd"
exit 1 //This should be exit and fail the bb pipeline but it will give a successfull message in pipeline after echo
 export BUCKET_KEY=$(run_cmd "python")

Hi team, i want to manually fail my bitbucket pipeline whenever there is some error in my python script. It exits the script but didn't show a failure message. 

I have also tried it by using all of these set commands  at the start of bash script but also this doesn't works for me.

set -euxo pipefail


How can it get rid out of this ?

1 answer

1 accepted

2 votes
Answer accepted

I solved this by using the below code:

//Calling the python script 

//It contains the status of the last executed command
if [[ $? -eq 0 ]]; then
echo "success*********"
exit 0
echo "failed************"
exit 1

 This works for me and it fails the bitbucket pipeline.

Ah!  BTW thats the better way to check return code of the command, but do not forget to return exit code from the python script.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,792 views 10 16
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