Answers: <p>Try and add a Stage condition to only run that stage for a specific branch.</p>
  <pre><code>condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
  
  
  stages:
  - stage: A
               .....
  
  - stage: B
    **condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))**
    jobs:
    - job: B1
      steps:
        - script: echo Hello Stage B!
        - script: echo $(isMain)
  </code></pre>
  <p>Reference : <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&amp;tabs=yaml" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&amp;tabs=yaml</a></p>
  <p>PS : Will refine the answer in future, currently we are still using GUI for releases and we are using this branch filter to control this scenario.</p>
  <p><a href="https://i.sstatic.net/GZWfa.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GZWfa.png" alt="enter image description here" /></a></p>
  
Answers: CC BY-SA 4.0
Answers: 2021-01-26T11:34:52.937Z
Answers: Thank you for your answer. At least in our current setup we want to still run the Build (which includes tests) for all branches. The only reason we don't want to run them for Branches with a PR is because a PR often gets a few commits in quick succession to fix comments of the reviewers.
Answers: Staeff
Answers: CC BY-SA 4.0
Answers: 2021-01-25T19:00:21.173Z
Answers: 2021-01-25T19:00:21.173Z
Answers: Vinay
Body: <p>Currently we have a build pipeline which checks if there is a PR for the current branch and if yes it sets a variable and skips the other build steps.</p>
  <p>But when this happens the Release still completes as Successful and a empty drop is created. This triggers a release which fails because drop is empty.</p>
  <p>This is the dumbed down version of the build pipeline:</p>
  <pre class="lang-yaml prettyprint-override"><code>    stages:
      - stage: CheckShouldBuildStage
        displayName: Check Should Build
        jobs:
        - job: CheckShouldBuildJob
          displayName: Check Should Build
          steps:
            - powershell: |
                  $doBuild = $True
                  $sourceBranchName=&quot;$env:BUILD_SOURCEBRANCHNAME&quot;
                  $buildReason=&quot;$env:BUILD_REASON&quot;
                  
                  # Get PR information for branch
                  ...
                  
                  if ($branchHasPr -eq $True -and $buildReason -ne &quot;PullRequest&quot; -and $buildReason -ne &quot;Manual&quot;) {
                     $doBuild = $False
                     Write-Host &quot;Pr Build found, and not the merged PR build. Cancelled build.&quot;
                  }
  
                  ...
  
                 if ($doBuild -eq $True) {
                    Write-Host &quot;DoBuildVar=YES&quot;
                    Write-Host &quot;##vso[task.setvariable variable=DoBuildVar;isOutput=true]YES&quot;     
                  } else { 
                    Write-Host &quot;DoBuildVar=NO&quot;
                    Write-Host &quot;##vso[task.setvariable variable=DoBuildVar;isOutput=true]NO&quot;
                  }
              name: CheckShouldBuildTask
              displayName: Check Should Build
      - stage: BuildAndTest
        condition: 
          eq(
            dependencies.CheckShouldBuildStage.outputs['CheckShouldBuildJob.CheckShouldBuildTask.DoBuildVar'], 
            'YES'
          )
        dependsOn: CheckShouldBuildStage
        displayName: Build and Test
        jobs:
           ...
  </code></pre>
  <p>What should be the correct way to skip a build and not trigger a Release? Is it possible to just disable the creation of an empty drop?</p>
  <p>I tried to disable the creation of an empty drop, but all my search results are just people where there was no drop created on mistake.. so this was a dead-end.</p>
  <p>I also know I can just fail my build pipeline but this would show up in the stats. As far as I can tell there really only is Success and Fail as a status for a pipeline. So this solution is also not working out for me.</p>
  
Comments: CC BY-SA 4.0
Comments: 2021-04-21T06:19:37.040Z
Comments: So the requirements are: For all branches that do not have a PR associated, run BuildAndTest, create an artifact and trigger Release. Is that correct?
Comments: qbik
Tags: <azure-devops><azure><azure-pipelines><build-pipeline>
Title: How to skip Build without creating Drop and not triggering Release in Azure DevOps
UserDisplayName: Staeff
ThreadText: # How to skip Build without creating Drop and not triggering Release in Azure DevOps
  
  (Asked by: username_0 on 2021-01-25)
  
  Currently we have a build pipeline which checks if there is a PR for the current branch and if yes it sets a variable and skips the other build steps.
  
  But when this happens the Release still completes as Successful and a empty drop is created. This triggers a release which fails because drop is empty.
  
  This is the dumbed down version of the build pipeline:
  
  ```yaml
      stages:
      - stage: CheckShouldBuildStage
        displayName: Check Should Build
        jobs:
        - job: CheckShouldBuildJob
          displayName: Check Should Build
          steps:
            - powershell: |
                  $doBuild = $True
                  $sourceBranchName="$env:BUILD_SOURCEBRANCHNAME"
                  $buildReason="$env:BUILD_REASON"
                  
                  # Get PR information for branch
                  ...
                  
                  if ($branchHasPr -eq $True -and $buildReason -ne "PullRequest" -and $buildReason -ne "Manual") {
                     $doBuild = $False
                     Write-Host "Pr Build found, and not the merged PR build. Cancelled build."
                  }
  
                  ...
  
                 if ($doBuild -eq $True) {
                    Write-Host "DoBuildVar=YES"
                    Write-Host "##vso[task.setvariable variable=DoBuildVar;isOutput=true]YES"     
                  } else { 
                    Write-Host "DoBuildVar=NO"
                    Write-Host "##vso[task.setvariable variable=DoBuildVar;isOutput=true]NO"
                  }
              name: CheckShouldBuildTask
              displayName: Check Should Build
      - stage: BuildAndTest
        condition: 
          eq(
            dependencies.CheckShouldBuildStage.outputs['CheckShouldBuildJob.CheckShouldBuildTask.DoBuildVar'], 
            'YES'
          )
        dependsOn: CheckShouldBuildStage
        displayName: Build and Test
        jobs:
           ...
  
  ```
  
  What should be the correct way to skip a build and not trigger a Release? Is it possible to just disable the creation of an empty drop?
  
  I tried to disable the creation of an empty drop, but all my search results are just people where there was no drop created on mistake.. so this was a dead-end.
  
  I also know I can just fail my build pipeline but this would show up in the stats. As far as I can tell there really only is Success and Fail as a status for a pipeline. So this solution is also not working out for me.
  
  **Tags:** azure-devops, azure, azure-pipelines, build-pipeline
  
  > **Comments:**
  > **username_1**: So the requirements are: For all branches that do not have a PR associated, run BuildAndTest, create an artifact and trigger Release. Is that correct?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-01-25. Score: 1
  
  Try and add a Stage condition to only run that stage for a specific branch.
  
  ```
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
  
  stages:
  - stage: A
               .....
  
  - stage: B
    **condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))**
    jobs:
    - job: B1
      steps:
        - script: echo Hello Stage B!
        - script: echo $(isMain)
  
  ```
  
  Reference : <https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml>
  
  PS : Will refine the answer in future, currently we are still using GUI for releases and we are using this branch filter to control this scenario.
  
  [![enter image description here](https://i.sstatic.net/GZWfa.png)](https://i.sstatic.net/GZWfa.png)
  
  > **Comments:**
  > **username_0**: Thank you for your answer. At least in our current setup we want to still run the Build (which includes tests) for all branches. The only reason we don't want to run them for Branches with a PR is because a PR often gets a few commits in quick succession to fix comments of the reviewers.  
  
  ---
  
  