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

时间:2021-04-19 16:11:40

标签: azure azure-devops azure-pipelines azure-pipelines-release-pipeline

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

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

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

Output variables input box

2 个答案:

答案 0 :(得分:0)

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

参考这篇 Stack Overflow 帖子:How to access the response of the InvokeRestAPI task from another job in an Azure DevOps pipeline?

$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"}

答案 1 :(得分:0)

然而,截至目前,不支持在 Gates 中的 Invoke REST API 中输出变量。

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

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

<块引用>

没有与此任务相关的输出变量。