Detecting if a Pipeline is running from a master/main branch in Azure Pipelines

You can essentially just define a variable:

  - name: isMaster
    value: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]

and then say you want to run a stage when upstream dependencies are successful and it’s in the master/main branch:

- stage: AwsDev
  displayName: "AWS Development"
  dependsOn: ["Build"]
  condition: "and(succeeded(), eq(variables.isMaster, true))"

That’s it!

Have a question⁉ Contact me.