Mandatory steps and/or mutiple pipelines

Hernán Vignolo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 20, 2023

Hi there!

I'm wondering if there's any chance to control which are the mandatory steps in a pipeline. By mandatory I mean: I have 2 steps and I always want to run step 2 regardless of the step 1 final status. I know that the after-script config is an option, but I'm looking for something else.

For example, something like this:

image: python:3.10

pipelines:
default:
- step:
name: Step 1
services:
- docker
script:
- echo "This step will run and might fail"
- exit 1
- step:
name: Step 2
services:
- docker
script:
- echo "This step will run regardless of Step 1" 

Is there any config like mandatory: false for a given step?

 

Additionally, I wonder if there's a way to have more than just one pipeline (something like bitbucket-pipelines-2.yml), like in Github where I can create several ones in the .github/workflows directory and each one runs independently, and I can configure which pipeline must block a PR merge for example.

Thanks!

1 answer

1 accepted

0 votes
Answer accepted
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 22, 2023

G'day, @Hernán Vignolo 

Welcome to the community.

In a serial step process, when a step fails, the build exits with code 1, and the pipeline is considered to have failed. While Bitbucket Cloud doesn't provide a direct way to configure a step as 'mandatory,' it is possible to instruct the pipeline not to exit the process with a non-zero exit code. This allows the pipeline to proceed to the next steps, even if the step has failed.

This method utilizes "set +e" on the commands that you suspect may failed. For example:

image: python:3.10

pipelines:
default:
- step:
name: Step 1
services:
- docker
script:
- set +e echo "This step will run and might fail"
- step:
name: Step 2
services:
- docker
script:
- echo "This step will run regardless of Step 1" 

This will force Step 2 to trigger even if the commands in Step 1 failed. We have a KB that explains this more in-depth at:

 Pipelines builds succeeds even on command failure 

Regarding having two bitbucket-pipelines.yml, this is unfortunately not possible but if you are looking into triggering it separately, you may consider using pipeline start conditions to specifically trigger specific pipeline build independently:

Pipeline start condition 

I hope this helps.

Regards,
Syahrul

Hernán Vignolo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 23, 2023

Thanks!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events