Using the pool system:
You have an agent in your pool "usable agents" affected to your project.
At 6PM, using a teamcity build configuration, you can execute a custom script, which will affect your machines to the pool "usage agents".
At 6AM, an other script will affect this agents to an other pool : "unusable agent", which is not affected to any configuration.
Here is the teamcity resource : https://confluence.jetbrains.com/display/TCD10/REST+API#RESTAPI-AgentPools
A base of implementation would be, in powershell :
In this case, AgentId is the id of your agent your want to move.
And PoolId, is the targeted pool identifier.
You can get the ids of your pool on this URL:
http://teamcityURL/app/rest/agentPools/
You can get the ids of your agents on this URL:
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
}
Your current user need to have the role : Manage agent pools
In my case, considering pools like:
| Id | Pool |
| 1 | Usage agents |
| 2 | Unusable agents |
| Id | Agent |
| 1 | AllDay |
| 2 | Nightly1 |
| 3 | Nightly2 |
Executing at 6PM:
Powershell Configuration running: AgentToPool.ps1
With parameters -AgentId:2 -PoolId:1
Powershell Configuration running: AgentToPool.ps1
With parameters -AgentId:3 -PoolId:1
Executing at 6AM:
Powershell Configuration running: AgentToPool.ps1
With parameters -AgentId:2 -PoolId:2
Powershell Configuration running: AgentToPool.ps1
With parameters -AgentId:3 -PoolId:2