You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
#!/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 ?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.