Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
param([String]$XenServerPoolMaster, [String]$TemplateName, [int]$NumberOfBuildAgents)
Add-PSSnapIn XenServerPSSnapin
. ".\credentials.ps1"
. ".\teamcity.ps1"
Connect-XenServer -Server $XenServerPoolMaster -Creds (Get-XenServerCredential) -NoWarnNewCertificates -NoWarnCertificates
function private:New-BuildAgentVM([string]$XenServerPoolMaster, [string]$templateName, [int]$buildAgentIndex) {
$buildagentName = "${templateName}-$buildAgentIndex-TEST"
# Clone the template to use a new name.
TeamCity-ReportBuildProgress "Cloning $TemplateName to create a new build agent $buildagentName"
Invoke-XenServer:VM.Clone -Server $XenServerPoolMaster -VM $templateName -NewName $buildagentName | Out-Null
TeamCity-ReportBuildProgress "Setting 'active' tag on $buildagentName"
$tags = Get-XenServer:VM.tags -Server $XenServerPoolMaster -VM $templateName
$tags += "active"
Set-XenServer:VM.tags -Server $XenServerPoolMaster -VM $buildagentName -tags $tags
TeamCity-ReportBuildProgress "Starting $buildagentName"
# Provision the template to convert it to a runnable VM
Invoke-XenServer:VM.Provision -Server $XenServerPoolMaster -VM $buildagentName
# Start the new VM
Invoke-XenServer:VM.Start -Server $XenServerPoolMaster -VM $buildagentName
return $buildagentName
1..$NumberOfBuildAgents |% {
TeamCity-ReportBuildProgress "Creating new build agent $_"
$buildAgentName = (New-BuildAgentVM $XenServerPoolMaster $TemplateName $_)[-1] # The build agent name is the last thing returned from the function.
TeamCity-ReportBuildProgress "Waiting for $buildAgentName to come up"
do {
# Wait for the VM to finish spinning up, then we can get its IP address for remote connections
$vmNetworks = (Get-XenServer:VM.GuestMetrics -VM $buildAgentName).networks
} while ($vmNetworks -eq $null)
$buildAgentIP = $vmNetworks["0/ip"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.