You can download the ARM template from here.

Pre-Requisites:

>>You have Agent pool created. The build agent will be added to this Agent pool.

>>Make sure vNet, Subnet and resource group are already created and available.

Now login to https://dev.azure.com/<your project> and upload the following file to the Repos-

  1. azuredeploy.json
  2. azuredeploy.parameters.json
  3. Ubuntu-vstsbuildagent-install.sh

>>Make sure Ubuntu-vstsbuildagent-install.sh is uploaded to blob storage and the path added to azuredeploy.json file.

>> Now go to Pipelines–>Builds –> New Pipeline (select classic editor). Select the source, Team Project, Repository and continue

>>On Select a Template –> Start with an empty job

>>Now add a task – Publish Build Artifacts

>>In the task “Publish Artifact:drop“, change the “Path to Publish” to point to template folder

>>Save & queue to generate the build.

>>Once build is completed. On Summary tab, you can see the templates are published in drop artifact.

>>Now go to Pipelines–>Releases–>New Pipeline. Select empty job template. Select Add Artifacts and provide the values

>>Then add a stage to create the Windows build agent. Add a task Azure Resource group deployment and provide subscription (authorize it), resource group, location, template, “Override template parameters” etc and save.

Override template parameters

-vmName "$(vmName)"  -vmAdminUserName "$(vmAdminUserName)"  -vmAdminPassword "$(vmAdminPassword)" -VSTSAccount "$(VSTSAccount)" -PersonalAccessToken "$(PersonalAccessToken)" -poolName "$(poolName)"  -existingVirtualNetworkName "$(existingVirtualNetworkName)" -existingSubnetName "$(existingSubnetName)" -existingVirtualNetworkResourceGroupName "$(existingVirtualNetworkResourceGroupName)" -vmSize "$(vmSize)" -teamProject "$(teamProject)"

 

>>Create these parameters and assign values in Variables tab.

>>Create release to provision the VM and build agent.

>>Once completed you will see the VM and the agent in the pool as  below-