Azure DevOps 发布管道门中的输出变量

Output variables in Azure DevOps release pipeline gates

如何在 Azure DevOps 发布管道门中使用输出变量?

我想在 HTTP 请求的响应中输出一个等于某个值的变量。

例如http 请求将 return { success: true, userId: 12345 }。我想为 userId 设置一个变量,我可以在下一个 HTTP 请求门中使用它。

也许这不是您想要的,但您可以使用 Azure Powershell 调用 HTTP 请求并将响应值以这种方式输出到管道变量以供后续步骤使用。

参考这个 Stack Overflow Post:

$url = "https://vsrm.dev.azure.com/thecodemanual/$env:SYSTEM_TEAMPROJECTID/_apis/Release/definitions/$($env:RELEASE_DEFINITIONID)?api-version=5.0"
$pipeline = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer
$env:SYSTEM_ACCESSTOKEN"}

Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"
$buildNumber = $env:BUILD_BUILDNUMBER
$pipeline.variables.ReleaseVersion.value = $buildNumber

####****************** update the modified object **************************
$json = @($pipeline) | ConvertTo-Json -Depth 99
$updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}

然而,截至目前,不支持在 gates 中调用 REST API 输出变量。

输出变量部分不能输出自定义变量,只能输出任务定义的变量。

遗憾的是,此任务未定义输出变量。您可以在屏幕截图中看到它:

There are no output variables associated with this task.