如何使用 Azure DevOps Rest API 通过 powershell 获取发布状态(成功、失败)
How to get status of the release (success, failure) with powershell using Azure DevOps Rest API
我正在使用 post
方法在 Azure DevOps
中创建版本:
$url = "https://vsrm.dev.azure.com/"+$organization+"/"+$project+"/_apis/release/releases?api-version=5.1"
$body = @{definitionId = 9} | ConvertTo-Json -Depth 4
Invoke-RestMethod -Uri $url -Method POST -Body $body -ContentType "application/json" -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
我的管道很简单,只有一个自动执行的阶段。发布创建和执行工作正常。
但是如何使用 powershell
和 REST API
获取我的 stage/s 的状态。我需要在发布过程中继续执行脚本,并在任何阶段失败时启动脚本失败。
有什么想法吗?
使用 DefinitionID 和 EnvironmentID(您将从最初的 POST 响应中获得),您可以查询最后一个版本并定期检查 "deploymentStatus" 值,并在状态更改为 "succeeded/failed/cancelled".
(collectionURL)/(teamproject)/_apis/Release/deployments?definitionId="+RELEASE_DEFINITIONID+"&definitionEnvironmentId="+RELEASE_DEFINITIONENVIRONMENTID?api-版本=1.0
我正在使用 post
方法在 Azure DevOps
中创建版本:
$url = "https://vsrm.dev.azure.com/"+$organization+"/"+$project+"/_apis/release/releases?api-version=5.1"
$body = @{definitionId = 9} | ConvertTo-Json -Depth 4
Invoke-RestMethod -Uri $url -Method POST -Body $body -ContentType "application/json" -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
我的管道很简单,只有一个自动执行的阶段。发布创建和执行工作正常。
但是如何使用 powershell
和 REST API
获取我的 stage/s 的状态。我需要在发布过程中继续执行脚本,并在任何阶段失败时启动脚本失败。
有什么想法吗?
使用 DefinitionID 和 EnvironmentID(您将从最初的 POST 响应中获得),您可以查询最后一个版本并定期检查 "deploymentStatus" 值,并在状态更改为 "succeeded/failed/cancelled".
(collectionURL)/(teamproject)/_apis/Release/deployments?definitionId="+RELEASE_DEFINITIONID+"&definitionEnvironmentId="+RELEASE_DEFINITIONENVIRONMENTID?api-版本=1.0