简体   繁体   中英

Deploy to a different environment depending on the source branch

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?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM