Skip to content

Instantly share code, notes, and snippets.

@MarcusFelling
Last active December 26, 2017 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcusFelling/f1f2039d9d5ca11cb20ae17412ccdbac to your computer and use it in GitHub Desktop.
Save MarcusFelling/f1f2039d9d5ca11cb20ae17412ccdbac to your computer and use it in GitHub Desktop.
Chef recipe to install VSTS agents
# Array of agents to create
example_agents = ['Example-1', "Example-2", "Example-3", "Example-4", "Example-5", "Example-6"]
example_agentpool = ''
install_dir = 'H:\\agents\\'
sv_user = '' # Windows log on account for agent service
sv_password = ''
vsts_url = 'https://youraccount.visualstudio.com'
vsts_token = '' # Temporary PAT to use when installing the agents
# Download install files from S3
powershell_script 'Download vsts-agent-win-x64-2.126.0.zip' do
code <<-EOH
set-location 'C:\\temp'
read-s3object -bucketname S3BucketName -key vsts-agent-win-x64-2.126.0.zip -file vsts-agent-win-x64-2.126.0.zip -region RegionName
EOH
not_if { ::File.exist?('C:\\temp\\vsts-agent-win-x64-2.126.0.zip') }
end
# Loop through array of example_agents, create folder to install agent in, then install agent
example_agents.each do |agentname|
directory "#{install_dir}#{agentname}" do
rights :modify, 'Everyone'
inherits true
recursive true
not_if { ::File.directory?('#{install_dir}#{agentname}}') }
end
# If the agent Windows service does not already exist, install agent using name
powershell_script 'Install VSTS Build agent #{agentname}' do
code <<-EOH
Set-Location "#{install_dir}#{agentname}"
Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("C:\\temp\\vsts-agent-win-x64-2.126.0.zip", "$PWD")
$args = "--unattended --url #{vsts_url) --auth pat --token #{vsts_token) --pool example_agentpool --agent #{node['hostname']}-#{agentname) --runAsService --windowsLogonAccount #{sv_user) --windowsLogonPassword #{sv_password)"
Start-Process #{install_dir}#{agentname}\\config.cmd -ArgumentList $args -Wait
EOH
not_if { Win32::Service.exists?("vstsagent.AccountName.agentname") }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment