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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,466,075
Community Members
 
Community Events
176
Community Groups

How to manually fail a bitbucket pipeline in bash script

#!/bin/bash 

function run_cmd()
{
cmd=$1
eval $cmd

if [[ $? -eq 0 ]]; then
return
fi
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 beanstalk_deploy.py")

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 
python beanstalk_deploy.py

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

 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 beanstalk_deploy.py? I have tried exit(1) and sys.exit(1) but neither is working. Thanks

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events