在VSTS中,我可以批量更改代理队列吗? [英] In VSTS, can I bulk change the agent queue?

查看:103
本文介绍了在VSTS中,我可以批量更改代理队列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想将所有构建和发行版更改为新的代理队列,是否有办法一次完成所有操作?

If I want to change all of my builds and releases to a new agent queue, is there a way to do that all at once?

Agent Queue API 没有有关更改使用哪个队列的任何信息,并且

The Agent Queue API doesn't have anything about changing which queue is used, and the Build API doesn't have a variable for the queue name. In VSTS, in the Agent Pools tab in settings, I can see a list of pools and the builds that were run on them, but I don't see a way of changing them.

是否有一种编程方式可以一次全部更改它们?还是我必须手动进行全部更改?

Is there a programmatic way to change them all at once, or do I have to go through and change them all manually?

在每个版本上全面实施之前,我正在尝试一个特定的版本.现在我的程序流程是:获取构建定义,从具有正确构建的队列中获取队列代理,将旧版本中的队列设置为与新版本中的队列相同,然后将整个内容放入VSTS中.

I'm experimenting on a specific build before fully implementing it in on every build. My program flow right now is: get the build definition, get the queue agent from a build that has the right one, set the queue in the old version equal to the new one, and PUT the whole thing back in VSTS.

$result = Invoke-RestMethod -Method GET -Uri $uri -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$result3 = Invoke-RestMethod -Method GET -Uri $uri3 -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$q = $result3.queue
$result.queue = $q
$result | ConvertTo-JSON
Invoke-RestMethod -Method PUT $uri -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType "application/json" -Body $result

我遇到错误

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name:

如何从GET中正确配置PUT?

How do I properly configure the PUT from the GET?

推荐答案

REST API只能更改特定构建定义的代理队列.

The REST API can only change the agent queue for a certain build definition.

因此,您需要获取团队项目的所有构建定义,然后循环更改构建定义的代理队列.详细信息如下:

So you need to get all the build definitions for a team project, and then loop to change the agent queue for the build definitions. Details are below:

  1. 获取要用于构建定义的代理队列的ID

  1. Get the id for the agent queue you want to apply for the build definitions

使用获取队列列表 REST API:

Use the get a list of queues REST API:

GET https://account.visualstudio.com/DefaultCollection/project/_apis/distributedtask/queues?api-version=3.0-preview.1

在列出的代理队列中,找到要使用的代理队列的id.

In the listed agent queues, find the id of the agent queue you want to use.

就像您要使用Default代理一样,可以在以下步骤中将id用作7.

Such as if you want to use Default agent, you can use the id as 7 in the following step.

您可以获取每个构建定义的定义idrevision和定义name.

You can get each build definition’s definition id, revision and definition name.

循环每个构建定义并更改代理队列.更新构建定义,它需要构建修订和存储库信息.因此,您应该通过获取构建定义REST API :

Loop each build definition and change the agent queue. Updating build definition, it needs build revision and repository information. So you should to get the build definition repository by the get a build definition REST API:

GET https://account.visualstudio.com/DefaultCollection/project/_apis/build/definitions/definitionID?api-version=2.0

然后,您将获得类似于以下内容的存储库信息:

Then you can get repository information like:

"repository": {
        "properties": {
            "cleanOptions": "0",
            "labelSources": "0",
            "labelSourcesFormat": "$(build.buildNumber)",
            "reportBuildStatus": "true",
            "gitLfsSupport": "false",
            "skipSyncSource": "false",
            "checkoutNestedSubmodules": "false",
            "fetchDepth": "0"
        },
        "id": "e89075b8-d7bd-4c3f-b24c-23276d89e8ec",
        "type": "TfsGit",
        "name": "vs2017",
        "url": "https://marinaliu.visualstudio.com/Git2/_git/vs2017",
        "defaultBranch": "refs/heads/master",
        "clean": "true",
        "checkoutSubmodules": false
}

然后,您可以更新构建定义代理队列:

Then you can the update build definition agent queue:

PUT https://account.visualstudio.com/DefaultCollection/project/_apis/build/definitions/definitionID?api-version=2.0

Application/json as:
{
  "id": 6,
  "revision": 356,
  "queue": {
        "id": 7
    },
     "repository": {
        "properties": {
            "cleanOptions": "0",
            "labelSources": "0",
            "labelSourcesFormat": "$(build.buildNumber)",
            "reportBuildStatus": "true",
            "gitLfsSupport": "false",
            "skipSyncSource": "false",
            "checkoutNestedSubmodules": "false",
            "fetchDepth": "0"
        },
        "id": "e89075b8-d7bd-4c3f-b24c-23276d89e8ec",
        "type": "TfsGit",
        "name": "vs2017",
        "url": "https://marinaliu.visualstudio.com/Git2/_git/vs2017",
        "defaultBranch": "refs/heads/master",
        "clean": "true",
        "checkoutSubmodules": false
    }
}

当前项目中的内部版本定义现在都将代理队列更改为默认代理(如示例中的id = 7).您可以使用类似的方式来更改其他构建/发行版定义.

Now build definitions in the current project are all changing the agent queues as the default agent (id=7 as in the example). You can use a similar way to change other build/release definitions.

这篇关于在VSTS中,我可以批量更改代理队列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆