title: Extending my Azure DevOps Pipeline to include Build validation for all Pull Requests
body: <p>I have 30 or so Java Microservices that run of the same ci and cd template. i.e. Each of my Microservices has a build pipeline as follows and as shown below it runs automatically on a merge to master:</p>
  <pre><code>name: 0.0.$(Rev:r)
  
  trigger: 
    - master
  pr: none 
  
  variables:
  - group: MyCompany
  
  resources:
    repositories:
      - repository: templates
        type: git
        name: &lt;id&gt;/yaml-templates
  
  stages:
    - stage: Build
      jobs:
      - job: build
        displayName: Build
        steps:
        - template: my-templates/ci-build-template.yaml@templates
    - stage: PushToContainerRegistry
      dependsOn: Build
      condition: succeeded()
      jobs:
      - job: PushToContainerRegistry
        displayName: PushToContainerRegistry
        steps:
        - template: my-templates/ci-template.yaml@templates
  </code></pre>
  <p>Where ci-build-template.yaml contains...</p>
  <pre><code>steps:
    - checkout: self
      path: s 
  
    - task: PowerShell@2
  
    - task: Gradle@2
      displayName: 'Gradle Build'
  
    - task: SonarQubePrepare@4
      displayName: SonarQube Analysis
  
    - task: CopyFiles@2
      displayName: Copy build/docker to Staging Directory
  </code></pre>
  <p>I would like to implement pr build validation wherever someone raises a pr to merge into master. In the PR build only the Build stage should run and from the build template only some tasks within ci-build-template.yaml should run.</p>
  <p>A few questions for my learning:</p>
  <p>How can i uplift the yaml pipeline above to make the &quot;PushToContainerRegistry&quot; skip if it is a pr build?</p>
  <p>How can i uplift ci-build-template.yaml to make the &quot;SonarQubePrepare@4&quot; and &quot;CopyFiles@2&quot; skip if it is a pr build?</p>
  <p>And lastly how can i uplift the yaml pipeline above to enable build validation for all pr's that have a target branch of master?</p>
  <p>Whilst doing my own research i know you can do this via clickops but I am keep on learning on how to implement via yaml.</p>
  <p>thanks</p>