1

有三个构建代理可以运行我的 TC 配置。我只希望其中 1 个代理在白天运行构建,以便其他两个系统可用于手动测试。晚上 6 点之后,由于这些不会用于手动测试,我希望团队城市构建能够在所有三个系统上运行。任何想法我该怎么做?

提前致谢。

4

1 回答 1

1

使用泳池系统:

您的“可用代理”池中有一个代理会影响您的项目。

在下午 6 点,使用 teamcity 构建配置,您可以执行自定义脚本,这将影响您的机器到池“使用代理”。

早上 6 点,另一个脚本会将此代理影响到另一个池:“无法使用的代理”,这不会影响任何配置。

这是 teamcity 资源:https ://confluence.jetbrains.com/display/TCD10/REST+API#RESTAPI-AgentPools

在 powershell 中,实现的基础是:

在这种情况下,AgentId 是您要移动的代理的 ID。PoolId 是目标池标识符。

您可以在此 URL 上获取池的 ID: http://teamcityURL/app/rest/agentPools/ 您可以在此 URL 上获取代理的 ID: http://teamcityURL/app/rest/agents

#
# AgentToPool.ps1
#
Param(
    [Parameter(Mandatory=$true)][string]$AgentId = "0",
    [Parameter(Mandatory=$true)][string]$PoolId = "0"
)
Begin {
    $username = "guest"
    $password = "guest"
    $serverURL = "http://teamcityURL/"

    function Execute-HTTPPostCommand() {
            param(
                [string] $target = $null, 
                [string] $data = ""
            )

        $PostStr = [System.Text.Encoding]::UTF8.GetBytes($data)
        $request = [System.Net.WebRequest]::Create($target)

        $request.PreAuthenticate = $true
        $request.Method = "POST"
        $request.ContentLength = $PostStr.Length
        $request.ContentType = "application/xml"
        $request.Headers.Add("AUTHORIZATION", "Basic");
        $request.Accept = "*"
        $request.Credentials = New-Object System.Net.NetworkCredential($username, $password)

        $requestStream = $request.GetRequestStream()
        $requestStream.Write($PostStr, 0,$PostStr.length)
        $requestStream.Close()

        $response = $request.GetResponse()
        $xmlout = ""

        if($response)
        {
            $sr = [Io.StreamReader]($response.GetResponseStream())
            $xmlout = $sr.ReadToEnd()
        }
        return $xmlout;
    }  

    $data = "<agent id='$AgentId'/>"
    Execute-HTTPPostCommand $serverURL/app/rest/agentPools/id:$PoolId/agents $data
}

您当前的用户需要具有以下角色:Manage agent pools

就我而言,考虑以下池:

| 身份证 | 游泳池 |
| 1 | 使用代理 |
| 2 | 无法使用的代理 |
| 身份证 | 代理 |
| 1 | 全天 |
| 2 | 每晚1 |
| 3 | 每晚2 |

下午 6 点执行:

Powershell配置运行:AgentToPool.ps1 带参数-AgentId:2 -PoolId:1

Powershell配置运行:AgentToPool.ps1 带参数-AgentId:3 -PoolId:1

早上 6 点执行:

Powershell配置运行:AgentToPool.ps1 带参数-AgentId:2 -PoolId:2

Powershell配置运行:AgentToPool.ps1 带参数-AgentId:3 -PoolId:2

于 2017-01-06T13:26:32.743 回答