Hello everyone,
As part of the recent rework on our Bitbucket pipeline, I moved several deployment steps to run in parallel to reduce execution time. I also grouped these steps and applied the fail-fast: true option, so if one deployment fails, all other deployments to different servers are stopped, which is working as intended.
However, in the event of a failure, we need to perform cleanup tasks on the hosts, such as removing certain files or running checks to ensure everything is functioning correctly.
I’m now wondering if there’s a way to conditionally trigger a cleanup step specifically when fail-fast is activated.
Hi and welcome to the community!
A conditional step with a static bitbucket-pipelines.yml file is not possible.
It may be possible with dynamic pipelines but I am not 100% sure. You can post question in this group:
and ask if dynamic pipelines can address your specific use case. Please keep in mind that dynamic pipelines are available for workspaces on the Premium billing plan.
Another option is to use an after-script for each parallel step. In the after-script, you can check the step's exit code and if it is 0, you can exit the after script:
if [ "$BITBUCKET_EXIT_CODE" == "0" ]; then exit 0 ; fi;
Otherwise, the rest of the after-script's commands will be executed.
Please keep in mind that if you have three parallel steps and e.g. the first one fails, then the other two steps will be stopped. Only the first's step's after-script will get executed, as after-scripts don't run for stopped steps. So, you would need to include clean-up commands for all hosts in the after-script, and then use the same after-script in all parallel steps.
Please feel free to reach out if you have any questions!
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.