Home > Enterprise >  Deploy to a different environment depending on the source branch
Deploy to a different environment depending on the source branch

Time:10-21

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?

CodePudding user response:

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:

  • Related