I'm trying to assign one of 2 values to a variable in addition to variable group and can't find the reference that how to use IF ELSE.
Basically I need to convert this jerkins logic to azure DevOps.
Jenkins
if (branch = 'master') { env = 'a' } else if (branch = 'dev'){ env ='b' }
I found 1 reference from the following one, but this one seems to work if the variables section doesn't have variable groups.
https://stackoverflow.com/a/57532526/5862540
But in my pipeline, I already have a variable group for secrets, so I have to use name/value convention and the example doesn't work with the errors like expected a mapping
or A mapping was not expected
or Unexpected value 'env'
variables: - group: my-global - name: env value: ${{ if eq(variables['Build.SourceBranchName'], 'master') }}: env: a ${{ if eq(variables['Build.SourceBranchName'], 'dev') }}: env: b
or
variables: - group: my-global - name: env value: ${{ if eq(variables['Build.SourceBranchName'], 'master') }}: a ${{ if eq(variables['Build.SourceBranchName'], 'dev') }}: b
To use a variable group, open your pipeline. Select Variables > Variable groups, and then choose Link variable group. In a build pipeline, you see a list of available groups. In a release pipeline, for example, you also see a drop-down list of stages in the pipeline.
You could add two same tasks in the pipeline, one with the condition ((Var1==A || Var1==B || Var1==C) && (Var2==2)) and another with condition ((Var1==A) &&(Var2==1)) , this should be work.
Passing variables between tasks in the same jobSet the value with the command echo "##vso[task. setvariable variable=FOO]some value" In subsequent tasks, you can use the $(FOO) syntax to have Azure Pipelines replace the variable with some value.
This code works.
I'm doing similar with parameters.
variables: - name: var1 ${{ if eq(parameters.var1, 'custom') }}: value: $(var1.manual.custom) ${{ if ne(parameters.var1, 'custom') }}: value: ${{ parameters.var1 }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With