从Powershell脚本返回值到Azure devops任务



我有一个Powershell脚本返回一个字符串值。我使用AzurePowerShell任务调用这个脚本,我想保留返回值,以便在同一管道内的后续任务中使用它。我该怎么做呢?有什么想法吗?

ScriptPowershelltest.ps1:

function a {
<<processing steps>>
return $(testString)
}

管道:

- task: AzurePowerShell@ 
ScriptPath: Powershelltest.ps1 (calls the above powershell script)
- task: AzureCLI@
inlineScript: | 
use the value from $testString(??)

我如何在第一个任务(AzurePowerShell)中捕获Powershell的返回值并在AzureCLI任务中使用它?

感谢

在第一个任务中使用此命令:##vso[task.setvariable variable=testString]$testString'。在第二个任务中,您将像这样调用变量:$(testString)。

你的函数应该如下所示:

function a {
<<processing steps>>
##vso[task.setvariable variable=testString]$testString'
}

如果只是想在后续步骤中使用该值,则不一定需要返回该值。

链接:https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&标签= yaml % 2 cbatch # expansion-of-variables

最新更新