Execute step for all branches AND specified branch

Pavel February 18, 2021

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

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 22, 2021

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

Pavel February 22, 2021

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

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 23, 2021

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

Pavel April 5, 2021

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
AUG Leaders

Atlassian Community Events