Reputation: 279
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.
Upvotes: 9
Views: 7584
Reputation: 163
I ran into this issue myself.
A workaround is to use two double quotes.
In powershell:
$foo -replace '"', '""'
Upvotes: 0
Reputation: 76918
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:
However, if we use the powershell
task to output it, it will remove quotation marks:
Write-Host "fooVariableInPipeline is $(fooVariableInPipeline)"
The output:
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:
Hope this helps.
Upvotes: 5