Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,295,683
Community Members
 
Community Events
165
Community Groups

Execute step for all branches AND specified branch

Edited

Is it possible to make a pipeline short and clear like this?

pipelines:  
default:    
parallel:
      - step:
          nameSecurity Scan          
script:    
echo "security test all branches"
       - step: 
          
nameLint the node package
          script: 
           - 
echo "lint test all branches"
  branches:
    '{develop,master,staging}':
      - step:
          nameBuild image
          triggerautomatic
          script:
              - echo "building image"
    staging:
      - step:
          nameDeploy to staging
          triggerautomatic
          script:              
echo 'branch is deployed automatically'
    '{develop,master}':
       - step:
          nameDeploy to current branch env
          triggermanual
          script:
              - echo 'branch is deployed manually'

Instead of duplicating build and all other default steps inside all branches steps?
If i run the code above the jobs which are in the Default will be not triggered for specific branches. Specifying all these steps with anchors or duplicating them somehow is a bit messy. 
Do i have an option to specify jobs for all pipelines AND another job for a specific branch?
Thank you.

1 comment

Hi Pavel and welcome to the community.

Do i have an option to specify jobs for all pipelines AND another job for a specific branch?

I'm afraid that this is not possible. The default pipeline runs for all branches that don't have a branch-specific pipeline. If there is a branch-specific pipeline, the default will not run.

Having multiple branch-specific pipelines in the yml file is also something that won't work. The way to achieve what you want without much duplication in the code would be with yaml anchors.

Assuming that you want to have a default pipeline running for branches other than master, develop and staging, you could do something like the following (you can remove the default section if you don't want pipelines running on branches other than master, develop and staging)

 

definitions:
  steps:
    - step: &security-scan
        name: Security Scan
        script:
          - echo "security test all branches"
    - step: &lint
        name: Lint the node package
        script:
          - echo "lint test all branches"
    - step: &build-image
        name: Build image
        trigger: automatic
        script:
          - echo "building image"
    - step: &deploy-to-staging
        name: Deploy to staging
        trigger: automatic
        script:
          - echo 'branch is deployed automatically'
    - step: &deploy-to-current
        name: Deploy to current branch env
        trigger: manual
        script:
          - echo 'branch is deployed manually'

pipelines:
  default:
    - parallel:
      - step: *security-scan
      - step: *lint
  branches:
    '{develop, master}':
      - parallel:
        - step: *security-scan
        - step: *lint
      - step: *build-image
      - step: *&deploy-to-current
  staging:
    - parallel:
      - step: *security-scan
      - step: *lint
    - step: *build-image
    - step: *deploy-to-staging

 

Kind regards,
Theodora

Thank you. I did in the same way, but faced the problem of adding Deployment flag with variable to the steps. So in the current situation i have two choices 1) Mess in global pipeline variables but readable yml 2) Mess and lot or repeats in yml but split variables for each `deployment`.

bb.png

Hi Pavel,

Thank you for your reply. Are you doing deployments to more than one environment?

I'm not sure if you want manual_deploy and auto_deploy to deploy to the same or a different environment, and whether they have the same script or not. It would be useful to have a bit more context, so we can see how to address this.

Kind regards,
Theodora

Thank you for your response.

Yes, you are right, the manual and auto-deploy have only one difference - manual or auto-trigger for deployment. And yes, we are deploying to the different environments and we would like to have several "deployment" scopes with the variables but needs to reuse the yml steps. But as you can see on a screenshot we can not utilize "deployment" flag.

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,170 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you