Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Azure DevOps remove quotation marks when setting a pipeline variable via a script?

I have to set an array for an ARM Template within my Azure DevOps pipeline. I set my variable like this:


$foo = '["' + 'bar' + '"]'
Write-Host $foo
#######Assign Variables with Correct Value in pipeline
Write-Host "##vso[task.setvariable variable=fooVariableInPipeline]$foo"

The $foo value is fine which would be ["bar"] as expected. But when I inspect the value in the next tasks after setting the variable, it would remove the quotation marks and show the value as [bar].

This is rather strange and I am wondering if its me or is it a bug? Any workarounds?

For the time being, I have updated my file directly using powershell code.

like image 674
Nilay Avatar asked May 27 '26 01:05

Nilay


1 Answers

Does Azure DevOps remove quotation marks when setting a pipeline variable via a script?

This issue does not come from azure devops, but depends on the syntax of your next task.

If I use the command line task to output that variable, it works fine:

echo $(fooVariableInPipeline)

The output:

enter image description here

However, if we use the powershell task to output it, it will remove quotation marks:

Write-Host "fooVariableInPipeline is $(fooVariableInPipeline)"

The output:

enter image description here

To resolve this issue, we need to surround the variable with single quotes to make it a literal string, like:

$Testfoo= '$(fooVariableInPipeline)'

Write-Host "Testfoo is $Testfoo"

Now, it works fine:

enter image description here

Hope this helps.

like image 177
Leo Liu-MSFT Avatar answered May 30 '26 04:05

Leo Liu-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!