我有一个yaml管道,使用任务Azure Powershell任务https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-powershell?view=azure-devops
该脚本已具有任务输出,如下所示:
$output = ConvertTo-Json -InputObject @{
resourceName = "aseName"
resourceGroupName = "ResourceGroupName"
} -Compress
Write-Output "##vso[task.setvariable variable=output;]$output"
在后续任务中,在同一作业中。我需要使用它作为{output.resourceName}。通常,从设计师那里可以按照我想要的方式将其取出。但是对于 YAML,我无法弄清楚。
有什么指示吗?
就像引用任何其他变量一样:
$(output)
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#set-in-script
作为旁注,这可能会在未来为其他人节省一些时间。当您创建新阶段并想要引用变量时,还应在设置变量时添加"isOutput=true":
Write-Output "##vso[task.setvariable variable=output;isOutput=true]$output"
在 YAML 中引用输出变量时,请按如下方式调用该变量:
- stage:
displayName: someName
variables:
output: $[stageDependencies.<stageName>.<jobName>.outputs['<stepname>.output']]
jobs:
- job: SomeName
steps:
- task: SomeTask