3

I am trying to set environment in the Azure DevOps build pipeline conditionally based on the trigger branch.

I tried something like this:

jobs:
    - deployment: Deploy
      ${{ if eq(variables['Build.SourceBranch'], 'DEV') }}: 
        environment: DEV
      ${{ if eq(variables['Build.SourceBranch'], 'TEST') }}: 
        environment: TEST

however no luck.

Any ideas how to set it correctly?

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
romanzdk
  • 930
  • 11
  • 30

1 Answers1

2

Build.SourceBranch will contain refs/heads/ in front of the branch name:

Git repo branch: refs/heads/master

Git repo pull request: refs/pull/1/merge

If you want just the final name part (after the last /), use Build.SourceBranchName.

See:

jessehouwing
  • 106,458
  • 22
  • 256
  • 341