问题
Is it possible to configure a build so you can set which agent you want it to run on when you manually queue a build?
回答1:
Do you have any special in your scenario?
Generally, in VSTS you can select which agent (Hosted) you want to run directly when you manually queue a build:
UPDATE:
If you are using on-premise TFS (TFS 2015 in your scenario) or Private agent for VSTS. Then you can set Demands when you queue a build.
You can also queue build with the REST API and specify the demands which match the specific agent:
e.g.:
Param(
[string]$collectionurl = "http://server:8080/tfs/DefaultCollection/",
[string]$projectName = "0323ScrumTFVC",
[string]$keepForever = "true",
[string]$BuildDefinitionId = "1",
[string]$user = "username",
[string]$token = "password"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
function CreateJsonBody
{
$value = @"
{
"definition": {
"id": $BuildDefinitionId
},
"sourceBranch": "$/0323ScrumTFVC",
"demands":["Agent.Name -equals AgentNameHere"]
}
}
"@
return $value
}
$json = CreateJsonBody
$uri = "$($collectionurl)/$($projectName)/_apis/build/builds?api-version=2.0"
$result = Invoke-RestMethod -Uri $uri -Method Post -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
回答2:
It appears this is the only way on VSTS 2015:
No friendly drop-drown menu so you have to type it in.
来源:https://stackoverflow.com/questions/49971599/specifying-agent-at-queue-build-time-with-tfs-2015