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?

3
  • Check this answer to see if it helps you, seems like if you can change your jobs a bit, you can do this. stackoverflow.com/a/61654446/1238413 Commented Jan 24, 2022 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. Commented Jan 24, 2022 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? Commented Jan 24, 2022 at 16:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.