0

On a pipeline, I have two powershell tasks that read variables from different files, and I want to copy those variables into the same environment variable. This design is being used across multiple pipelines, and I can't change it.

The following code in the powershell script is used for that effect, which copies the variables read from the file, contained in the fileParameters object, into the envParameters object:

Write-Host "##vso[task.setvariable variable=envParameters;]$($fileParameters)"

The above would work well if I would be executing the task once. But since the task is executed twice, the second execution deletes all the envParameters properties read in the first script execution. Is there a way to update envParameters without deleting the already existing properties?

ccoutinho
  • 3,308
  • 5
  • 39
  • 47
  • Check this answer to see if it helps you, seems like if you can change your jobs a bit, you can do this. https://stackoverflow.com/a/61654446/1238413 – FoxDeploy Jan 24 '22 at 14:12
  • If you can't change jobs at that level, you can use your same approach reading from a file, just resaving the env values as a variable at the end of each step. – FoxDeploy Jan 24 '22 at 14:13
  • @FoxDeploy your first solution implies changes in many places. Regarding the second, the `fileParameters` contains already such values. Can you explain a little bit better your idea? – ccoutinho Jan 24 '22 at 16:49

0 Answers0