Run Self-Hosted Containerised Build Agents using Azure Container Instance and Azure DevOps

Running build agent in containers is a great solution for achieving flexibility and reducing the costs of maintaining build agents.

In this article, I will run through all the steps needed to start one.

The first step is creating a folder containing a Dockerfile.

We then create an Azure Container Registry.

az group create --name buildagent --location uksouth
az acr create --resource-group buildagent --name alberto --sku Basic

We build our image using an Azure Registry Task.

az acr build --registry alberto -t buildagent:v1.0 --platform windows .

In azure DevOps we create a personal access token that has “Read&Manage” permissions for “Agent Pools” and “Read&Execute” permission for “Build”.

We copy the token on a temporary location, we will need it soon!

Under Organisation Settings” -> “Agent Pools” we create a new self-hosted agent.

The admin user can be enabled by running:

az acr update -n alberto --admin-enabled true

This step is only recommended for this tutorial.

Then we look for the server and credentials:

az acr show --name alberto --query loginServer
az acr credential show --name alberto

Run the following command to create an Azure Container Instance

After some minutes the server will become available for our pipelines:

We connected a container build agent hosted in Azure Container Instance to Azure DevOps.

Using containers as build agents offer flexibility and reduces the costs of maintaining and updating virtual machines.

Alberto De Natale is a passionate tech-enthusiast software developer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store