Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Azure by (7k points)
edited by

Azure Pipelines has Expressions and Conditions, how can I assign one of two values to a variable, based on a condition.
Is there a way to accomplish this?

${{ if endsWith( variables['Build.SourceBranchName'], '/master' ) }}:
      buildVersion: variables['mavenVersion']
    ${{ else }}:
      buildVersion: variables['Build.SourceBranchName']

1 Answer

0 votes
by (31.9k points)
edited by

If you are using variable groups then you need to define additional variables as name-value pairs. To use conditional variable assignment that would be as follows:

variables:
- group: 'my-variable-group'
- name: myfirstadditionalvariable
  value: 100
- name: myconditionalvariable
  ${{ if eq( variables['Build.SourceBranchName'], 'master' ) }}:
    value: masterBranchValue
  ${{ if ne( variables['Build.SourceBranchName'], 'master' ) }}:
    value: featureBranchValue

Want to become Azure Developer, check out this Azure Tutorial

Want more insights on Azure, visit the Azure Online Course page.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...