In my pipeline I have a release variable named sourcefilenames with blank value In PowerShell task1 I assign this variable with a string array using:
Write-Output ("##vso[task.setvariable variable=sourcefilenames]$name")
Then on PowerShell task2 I reference that variable sucecssfully with:
Write-Host $(sourcefilenames)
And the values appear But when I try to assign it to another variable so I can loop through the contents of the array:
$sourcenames= $(sourcefilenames)
It triggers an error:
"The term 'sourcefilename1' is not recognized as the name of...."
What could be wrong here? I have tried:
- Declaring a new array in powershell task2
- Passing $(sourcefilenames) directly in the foreach
all to no avail.
In a nutshell what I want to do is to loop through the array passed from task1 to task2
$sourcenames= "$(sourcefilenames)". See this answer to the linked duplicate for an explanation.$(...)macros getting expanded to values without any awareness of how they fit in to PowerShell's syntax in the resulting command. The error message implies that the resulting line that PowerShell interpreted was verbatim$sourcenames= sourcefilename1, which predictably fails. Using"..."would result in$sourcenames= "sourcefilename1", which should not result in the same error.