如何在运行时在 Powershell 中设置、重置或覆盖 Azure Pipelines 中的变量?
How can I set, reset or over-write a variable in Azure Pipelines at runtime in Powershell?
在运行时在 Azure Pipelines 中设置变量在 Poweshell 1.0 和 2.0 中都不起作用
Write-Host "##vso[task.setvariable variable=sauce]crushed tomatoes"
如果我执行以下操作,则不会设置我可以在另一个步骤或管道中引用的任何值:
Write-Host "The value is: $env:sauce" # line 10
Write-Host "The value is: $(sauce)" # line 11
第 10 行的输出是
The value is:
第 11 行出现错误:
sauce : The term 'sauce' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\AzurePipelines\Agent\work\_temp\cf78918a-9bc2-4874-ad26-fbc3c5165627.ps1:11
我尝试了其他几种方法,甚至我创建了一个变量和一个变量组,试图覆盖值,但没有任何效果。即使我确实设置了 cehcked 框 "settable at queue time" 框。
通过
设置变量
Write-Host "##vso[task.setvariable variable=sauce]crushed tomatoes"
将在任务完成后工作,管道将读取控制台并设置变量,因此您可以在任何其他步骤中使用它。
因此,如果您想打印,您必须在设置它的地方进行第一步,在使用它的地方进行其他步骤。
在运行时在 Azure Pipelines 中设置变量在 Poweshell 1.0 和 2.0 中都不起作用
Write-Host "##vso[task.setvariable variable=sauce]crushed tomatoes"
如果我执行以下操作,则不会设置我可以在另一个步骤或管道中引用的任何值:
Write-Host "The value is: $env:sauce" # line 10
Write-Host "The value is: $(sauce)" # line 11
第 10 行的输出是
The value is:
第 11 行出现错误:
sauce : The term 'sauce' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\AzurePipelines\Agent\work\_temp\cf78918a-9bc2-4874-ad26-fbc3c5165627.ps1:11
我尝试了其他几种方法,甚至我创建了一个变量和一个变量组,试图覆盖值,但没有任何效果。即使我确实设置了 cehcked 框 "settable at queue time" 框。
通过
设置变量Write-Host "##vso[task.setvariable variable=sauce]crushed tomatoes"
将在任务完成后工作,管道将读取控制台并设置变量,因此您可以在任何其他步骤中使用它。
因此,如果您想打印,您必须在设置它的地方进行第一步,在使用它的地方进行其他步骤。