To build your code or deploy your application using Azure pipelines, you need at least one agent. As you add more code and people, you’ll eventually need more. There are typically two types of agents we can setup in Azure DevOps.
- Self Hosted Agent
- Microsoft Hosted Agent

Microsoft Hosted Agent
Azure Pipelines provides a Microsoft hosted agent pool named Azure Pipelines that offers various virtual machine images to choose from, each including a broad range of tools and software
Self-Hosted Agent
An agent that you setup and manage to run build and release jobs is a self-hosted agent. Self-hosted agents give you more control to install dependent software needed for your builds and deployments. Also, machine-level caches and configuration persist from run to run, which can boost speed.
Note: Before you install a self-hosted agent you might want to see if a Microsoft-hosted agent pool will work for you. In many cases this is the simplest way to get going. However, you occasionally need additional processing power, disk space, or time to build your applications.
In this article, you learn how to set up your own build agent using Desired State Configuration in Azure Automation account .
In a standard scenario, you can setup a new self hosted build agent manually from Azure DevOps portal, But when you have multiple projects configured in Azure DevOps to run multiple pipelines, you might need to setup different pools for each project. Automating the process for build agent setup during provisioning of build agent VM will reduce time, efforts and complexity.
Step 1: Authenticate with a personal access token (PAT)
Sign in with the user account you plan to use in your Azure DevOps organization (https://dev.azure.com/{your_organization}
).
From your home page, open your user settings, and then select Personal access tokens.

Create a new Personal Access Token.

Copy the token. You’ll use this token while creating Credentials in the Automation account
Step 2: Create Azure Automation account
Sign in to the Azure portal. Select + Create a Resource. Search for Automation. In the search results, select Automation.

Create Credentials

Once the credentials are added, add a new DSC configuration file.
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
$accountCredential = Get-AutomationPSCredential 'VstsAccountCredentails'
configuration BuildAgentDSCConfig
{
Import-DscResource -ModuleName VSTSAgent
Node localhost
{
File CreateFolder {
Type = 'Directory'
DestinationPath = 'C:\VSTSAgents\'
Ensure = "Present"
}
xVSTSAgent VSTSAgent {
Name = "$env:COMPUTERNAME"
Pool = 'buildagents1'
ServerUrl = "https://dev.azure.com/<orgName>"
AccountCredential = $accountCredential
AgentDirectory = 'C:\VSTSAgents\'
Work = 'C:\_work\'
Ensure = 'Present'
PrefixComputerName = $true
DependsOn = "[File]CreateFolder"
}
}
}
Compile the DSC configuration and attach a build agent VM node to the configuration. Once the VM node is onboarded to the DSC, DSC pull server will perform a check on a fix interval to make sure that the VM is up and running as a build agent in Azure DevOps.