Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to run the same pipeline steps on master and pull-requests only

Aaron Bauman
Contributor
September 10, 2019

Scenario:

I have a ~10 line pipeline step that I want to define once and run against every commit to master, every time a PR is created, and every commit to a branch with an open PR.

How can I define a pipelines config to do this, with as little repetition as possible? I'd like to avoid re-defining the exact same step 2 or 3 times.

1 answer

1 accepted

1 vote
Answer accepted
Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 11, 2019

Hi @Aaron Bauman

I hope that this example can help you to reproduce the configuration:

definitions:
  step: &myCommonStep
    script:
      - echo "command 1"
      - echo "command 2"          

pipelines:
  pull-requests:
      '**':
         - step: *myCommonStep
           
  branches:
    master:
       - step: *myCommonStep
      
  default:
     - step:
        script:
          - echo "command 3"
          - echo "command 4"

In the example above the step myCommonStep will only run for pull requests and the master branch (running commands 1 and 2). All other commits coming to different branches will trigger the default section which will run command 3 and 4 only.

Let me know if you have more questions about this.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events