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

#!/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

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

Suggest an answer

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

Contest: Share your custom Bitbucket Pipe and win

Announced in this blog, this holiday season we’re celebrating all things CI/CD and between now and the end of 2019 we’ll be showcasing content, use cases, feature announcements and more. One featur...

1,042 views 4 4
Join discussion

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