0

I have a variable group that I want to be run an expression in. That is I want to have the variable group's variable contents be computed at runtime.

Variables_General has a variable called isMain with the content $[contains(variables['Build.SourceBranch'], 'refs/heads/develop')]

variables:
  - group: Variables_General

...

condition: variables.isMain

But this isn't working as desired. I've tried various combinations of double quoting, using $[],and $(). I've tried this in both the variable value and how the variable is referenced. It does one of two things, Says it wasn't expecting "$" or simply detects that the variable has content and therefore is "true"

What is the correct way to have code in a variable group's variable's value that gets evaluated at runtime?

Damon Stamper
  • 378
  • 1
  • 4
  • 16

1 Answers1

1

Yaml reference the variable group, but can not parse the expression. Yaml treats the $[contains(variables['Build.SourceBranch'], 'refs/heads/develop')] in variable group as characters.

You may submit a suggestion on the website below:

https://developercommunity.visualstudio.com/content/idea/post.html?space=21

Currently, you may define the isMain variable separately in the variables:

variables:
- group: Variables_General
- name: isMain 
  value: $[contains(variables['Build.SourceBranch'], 'refs/heads/master')]

steps:
- script: echo Hello!
  condition: eq(variables.isMain, true)
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • https://developercommunity.visualstudio.com/idea/1159166/allow-expressions-in-variable-groups-to-be-parsed.html for reference in case anybody wants to vote on it. – Damon Stamper Aug 21 '20 at 20:48