Some branches have shared steps & first step cannot be manual

Monica Gordillo April 8, 2021

I have the following deployments:

  • Test
  • Security
  • Staging
  • Production

I have steps associated with each deployment.  Each deployment has deployment variables associated with it.

I would like to run the "Test" & "Security" steps on all branches.  I would like the "develop" branch to run the steps for "Test", "Security" & "Staging".  I would like the "master" branch to run the steps for "Test", "Security", "Staging", and "Production".  Any other branches like "feature/*" only run steps for "Test" & "Security".  

The "Production" steps have a manual trigger.

I tried doing a combination of default: and branches:, but it looks like default: only runs on NON-MATCHED branches.  

 

Any suggestions will be greatly appreciated.

 

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 9, 2021

Hi @Monica Gordillo ,

Since you want to reuse the same steps for different branches, I would suggest using YAML anchors to define these steps.

You can check the following doc for more information on YAML anchors:

Based on the description of your deployments and also which deployments you want to run for a specific branch, I believe you could structure your bitbucket-pipelines.yml file as follows:

definitions: 
steps:
- step: &test
name: Test
deployment: Test
script:
- echo "Test deployment"
- step: &security
name: Security
deployment: Security
script:
- echo "Security deployment"
- step: &staging
name: Staging
deployment: Staging
script:
- echo "Staging deployment"
- step: &production
name: Production
deployment: Production
trigger: manual
script:
- echo "Production deployment"

pipelines:
default:
- step: *test
- step: *security
branches:
develop:
- step: *test
- step: *security
- step: *staging
master:
- step: *test
- step: *security
- step: *staging
- step: *production

The section with the keyword definitions defines each deployment step as an anchor, so you can reuse it later.
Then, the pipelines section defines which steps to run depending on the branch.

Is this something that works for you?

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events