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:

    - stage: CheckShouldBuildStage
      displayName: Check Should Build
      - job: CheckShouldBuildJob
        displayName: Check Should Build
          - powershell: |
                $doBuild = $True
                # 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
      dependsOn: CheckShouldBuildStage
      displayName: Build and Test

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.

  • 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?
    – qbik
    Commented Apr 21, 2021 at 6:19

1 Answer 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'))

- stage: A

- stage: B
  **condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))**
  - job: B1
      - 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

  • 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.
    – Staeff
    Commented Jan 26, 2021 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.