Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 598
romanzdk Avatar asked Nov 14 '25 11:11

romanzdk


1 Answers

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:

  • https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
like image 144
jessehouwing Avatar answered Nov 17 '25 10:11

jessehouwing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!