user10285265
user10285265

Reputation:

echo value of coalesced variable in yaml with azure devops

I have this variable in yaml

sonarVerbose: $[coalesce(variables['SonarVerbose'],false)]

and then I would like to output it which I do like this

- script: | 
   echo value is ${{variables.SonarVerbose}}

but it echo's [coalesce(variables['SonarVerbose'],false)] and not an expected 'false'.

Is this not possible ?

Upvotes: 1

Views: 10065

Answers (2)

Jane Ma-MSFT
Jane Ma-MSFT

Reputation: 5222

How to solve this issue:

You can replace your output script with the following script.

- script: | 
   echo value is $(variables.SonarVerbose)

The cause of the issue:

This issue arises because you are using compile time expression ${{ <expression> }} instead of run time expression $( <expression> ).

The ${{ <expression> }} will be evalusted before the yaml files executes. So the value is undefined at this point. It shows the expression itself, not the result of the expression evaluation.

Click this document for detailed information.

Upvotes: 2

Krzysztof Madej
Krzysztof Madej

Reputation: 40603

It looks that self assignment is not possible. As workaround you may use this:

variables:
  sonarVerboseNew: $[coalesce(variables.sonarVerbose,false)]

steps:
- script: echo $(sonarVerboseNew)
- bash: echo "##vso[task.setvariable variable=sonarVerbose;]$(sonarVerboseNew)"
- script: echo $(sonarVerbose)

Upvotes: 2

Related Questions