如何使用Dev Ops Rest Api在Dev Ops中对构建进行排队

时间:2019-08-20 15:43:44

标签: azure-devops-rest-api

如何使用Dev Ops Rest Api将构建排入队列。

到目前为止我尝试过的事情:

工作:

`https://${config.azureEndpoints.instance}/${config.azureEndpoints.collection}/${config.azureEndpoints.project}/_apis/build/builds?api-version=5.1
body: 

              definition: {
                id: 448
              },
               queue: {
                 id: buildId,
                 name: 'Hosted VS2017',
                 pool: {
                   id: 4,
                   name: 'Hosted VS2017',
                   isHosted: true
                 }
               },
              parameters: `{"parameters":"${parameters}"}`,

不起作用:

Body:
id: 546
name: "Azure Pipelines"
pool: {id: 25, name: "Azure Pipelines", isHosted: true}
id: 25
isHosted: true
name: "Azure Pipelines"

Error: 
Provisioning request delayed or failed to send 3 time(s). This is over the 
limit of 3 time(s). 

[Warning 1]
There was a failure in sending the provision message: Unexpected response 
code from remote provider InternalServerError 

这些值来自:

https:// $ {config.azureEndpoints.instance} / $ {config.azureEndpoints.collection} / $ {config.azureEndpoints.project} / _apis / build / definitions?$ {definitionId}&api-version = 5.1 < / p>

当手动触发时,我捕获了来自dev ops gui的请求。它执行相同的操作,但是添加:

agentSpecification: {identifier: "ubuntu-16.04"}

但是此值不在“定义”中,也没有端点来获取可能的agentSpecifications。

TLDR:如何使用Dev Ops中的现有定义在Dev Ops中对构建进行排队?

2 个答案:

答案 0 :(得分:0)

  

如何在Dev Ops Rest Api中将Dev Ops中的版本排队?

只需在请求正文中指定内部版本 definitionId ,即可通过API对该内部版本进行排队。

这是示例脚本,对我而言效果很好,您可以尝试以下方法:

$headers = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
$body = '
{ 
        "definition": {
            "id": {build definition id}
        } 
}

$Uri = "https://{instance}/{collection}/{project}/_apis/build/builds?api-version=5.1-preview.2"
$buildresponse = Invoke-RestMethod -Method Post -UseDefaultCredentials -ContentType application/json -Uri $Uri -Body $bodyString -Headers $headers

您可以看到,如果该构建成功通过API排队,您将看到有关排队时间和排队的用户的详细信息。

enter image description here

答案 1 :(得分:-1)

您可以只使用VSTeam来为您排队构建,也可以使用review the code of VSTeam来查看它是如何完成的。 API的官方文档为here

相关问题