Is there a way to block a pipeline from running if a branch already exists?

Ron S
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!
May 30, 2023

We want to setup test branches for our repository (e.g. test/*). We want to automatically run the pipeline for anytime a branch with the prefix of "test/" (e.g. test/new-feature) is updated.

However, we only want 1 active "test/" branch and block the pipeline if another developer pushes a branched called "test/other-new-feature". This way code in the test environment doesn't get overridden by mistake.

Is this possible within pipeline YML file?

Thanks.

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 31, 2023

Hi Ron,

If you configure a branch pipeline for test/*, it is going to run for all branches with the "test/" prefix.

What you could do instead is use in the bitbucket-pipelines.yml file the exact name of the branch, e.g. test/feature-a. When you finish with this branch and you want to use another test branch for builds, you can edit the bitbucket-pipelines.yml file and change test/feature-a to the name of this other test branch.

Is this something that works for you?

Kind regards,
Theodora

Ron S
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!
June 1, 2023

Hi Theodora,

 

Thanks for the suggestion. That's definitely one way to handle this, however, it won't stop the issue of another developer potentially pushing a test/something-new without checking and overriding the first test/new-feature branch.

Cheers,

Ron

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 2, 2023

Hi Ron,

I understand your concern.

You mentioned in your question

This way code in the test environment doesn't get overridden by mistake.

If the pipeline has a deployment step or stage, then with the Premium plan you can restrict the branches that are allowed to deploy to a certain deployment environment.

This can be done by admins from Repository settings > Deployments > select a deployment environment > you will see an option Branches allowed to deploy to <deployment_enviornment_name>:

In there, an admin can specify which branches are allowed to deploy to this specific environment.

This would need to be updated every time you want to have deployments run for a different test branch.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events