Overview
This article can help you set up fully automated deployment of Azure DevOps build agents. It explains step-by-step instructions on how to set up automated deployment of self-hosted agents using Azure DevOps Pipelines.
It is based on article VSTS/TFS automated build agent provisioning.
Problem
Setup and maintenance of build agents may be a daunting task. It requires configuration of Windows OS, installation of different development tools (like Visual Studio), etc. And then, when it is done, from time to time it is required to update the software, or install new software, or install security patches. This may be very time consuming.
Solution
Very easy solution
Microsoft provides Microsoft-hosted agents with different configurations. These agents are ready to use. Microsoft simply does all the hard work for you.
Custom solution
There might be situations where it’s not possible to use Microsoft-hosted agents. For example:
- Custom software or special configuration is required on the agent.
- Agent must be in Azure Virtual Network to have access to specific resources or VPN.
- Agent must have pre-installed certification keys (bad practice).
- Your product must comply with regulations of complete reproducibility, meaning that every build of your software must be reproducible by using the exactly same version of tools, operating system and patches. This is not possible with Microsoft-hosted agents because they are upgraded every month.
In such a case, you have to maintain your self-hosted agent by yourself. And this is what you need before you start:
- Azure DevOps organisation – I assume you already have this. And therefore, you need a build agent.
- Azure subscription – This article helps you to deploy agents in Microsoft Azure. If you want to use a different cloud provider or your own datacenter, you may use some scripts from here, but some parts must be implemented by yourself.
And there you have it! These are the tasks for setting up automated deployment of self-hosted build agents. Following tasks refer to GitHub repository that contains scripts for deployment.
After the automated deployment is set up, it is very easy to upgrade or redeploy the build agent. First, upgrade the configuration source code for Packer. Then queue new build Build Agent Image. Finally, create new release Azure DevOps Build Agent.