Hi Folks,
Need your help in one thing. I have a BB pipeline which consist of 4 steps . If Any of 3 steps failed there should be option for me to run 4th step directly.
Scenario : If any of step gets failed the 4th step should run with a manual trigger.
How Can I Achieve that. Any help is highly appreciated .
Hello @Shrey ,
Thank you for reaching out to Atlassian Community!
I'm afraid that currently, Bitbucket cloud pipelines will not continue to the next steps when a step failed. Whenever a step fails, the pipeline execution will be stopped and none of the next steps will be executed. We do have a feature request to implement an option to allow a step to fail and continue to the following steps :
We encourage you to add your vote there, so it gives that feature traction, and also add yourself as a watcher to be notified of any update on that feature implementation.
While that option is not available, you might be interested in using the after-script option in your step. The after-script section will always be executed at the end of a step, regardless if the step succeeded or failed. You could add some logic to the after-script section for it to run only when the step fails, like in the below example :
pipelines:
default:
- step:
name: Step 1
script:
- echo "test step"
after-script:
- if [[ BITBUCKET_EXIT_CODE -eq 0 ]]; then exit 0; else echo "Step failed" ; fi
- echo "only execute this if step failed"
In this example, in the after-script section, we are evaluating the value of the variable BITBUCKET_EXIT_CODE
that will contain the exit code of the last command executed in the step. If this exit code is zero (meaning the step's script commands were executed successfully) the after-script section will be forced exit. On the other hand, if BITBUCKET_EXIT_CODE
is different than zero (meaning one of the step commands has failed) the after-script section will be executed up to its end, so you can include any commands there that you would like to be executed only on step-failure.
For more details about the after-script section you can check our official documentation below :
Thank you, @Shrey !
Patrik S
after-script:
- if [[ BITBUCKET_EXIT_CODE -eq 0 ]]; then exit 0; else echo "Test failed!"; fi
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.