Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


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

3 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.

@jawad_abbasi How do you exit a non-zero code in your I have tried exit(1) and sys.exit(1) but neither is working. Thanks

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events