如何使用 rest api 在 Azure devops 部署组中获取选定机器的部署

how to get deployments for selected machine in Azure devops deployment groups using rest api

我正在编写脚本以从 Azure DevOps 为选定的 Azure DevOps 部署组和选定的目标计算机获取部署

以下使用休息apiurl未提供所需数据-

$connectionToken = ""

$Url1 = "https://dev.azure.com/{Org Name}{Project Name}/_apis/distributedtask/deploymentgroups? 
name={name}&api-version=6.0-preview.1"

$base64AuthInfo= 
[System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))

$json = Invoke-RestMethod -Uri $Url1 -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get

$data = $json | ConvertTo-Json -Depth 100 

$data

我需要做哪些其他 api url 更改才能获取所需数据?

What rest api url changes I need to do for getting required data ?

您可以尝试以下 URL 来获取部署作业:

https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/distributedtask/deploymentgroups/{DeployGroup ID}/deploymentTargetJobRequests?targetId={TargetMachineID}&api-version=6.1-preview.1

您可以在 Azure Devops url:

中获得 deploygroup idtarget machine id

mgid = deploygroup id machineid = target machine id.

这是 Powershell 示例:

$connectionToken = "PAT"

$Url1 = "https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/distributedtask/deploymentgroups/{DeployGroup ID}/deploymentTargetJobRequests?targetId={TargetMachineID}&api-version=6.1-preview.1"

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))

$json = Invoke-RestMethod -Uri $Url1 -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get

$data = $json | ConvertTo-Json -Depth 100 

$data

结果: