0

Is it possible to have different variable template files that would be used based on the branch being built? I was trying to do something like this:

jobs:
- job: BuildandPublish
  variables:
    - template: /env/$(Build.SourceBranchName).vars.yml

But that doesn't work, I'm guessing do to the order that those variables are replaced.

1 Answer 1

1

Is it possible to have different variable template files that would be used based on the branch being built?

From your YAML sample, you are using the format: $(Build.SourceBranchName). The variable value will be expanded at runtime.

But the template will read the variable at Compile time.

To solve this issue, you need to change the format : ${{ variables['Build.SourceBranchName'] }}

Here is an example:

jobs:
- job: BuildandPublish
  variables:
    - template: /env/${{ variables['Build.SourceBranchName'] }}.vars.yml
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I had tried similar syntax based on learn.microsoft.com/en-us/azure/devops/pipelines/process/… but it didn't work. I had tried ${{ variables.Build.SourceBranchName }}
we can also use the standard naming process in the environment variable and link to pipeline and use it to replace step using Build.SourceBranchName , ex - dev-tokenname, uat-tokenname

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.