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 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
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,119 views 0 7
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