How to set up an Azure DevOps YAML pipeline that deploys self-hosted build agents on Azure Container Instance

My GitHub repo shows you how to set up an Azure DevOps (ADO) pipeline that deploys ADO self-hosted build agents to Azure Container Instance (ACI). This allows you to host multiple build agents in your own subscription for parallel build/deployments or to have access to a vNet you control. The ADO build agents are running on each container in the container group and will regularly ping Azure DevOps listening for work.


Explanation of pipeline

This pipeline has 3 major stages:

  • Deploy initial infrastructure. This includes an Azure Container Registry & Log Analytics
  • Build the Docker image that contains the Azure DevOps build agent
  • Deploy the Azure Container Instance that will host the ADO build agents

The entrypoint for the pipeline is the /ado/infra/central/azure-pipeline.yml file.


You can see that the pipeline pulls in some variables from files. These are variables we want to check into source control because they are not secrets & are the same for all runs (whereas the PAT that allows the ADO agents to authenticate with ADO is a secret and should not be checked into source control)

This is an ADO deployment job. You can deploy to Azure using YAML pipelines instead of classic Release pipelines. You can also see that this uses a Microsoft hosted build agent ubuntu-latest. This is to boot-strap the environment. After this pipeline runs, the self-hosted agent pool you created will have multiple build agents available for other pipelines to use.

Finally, you can see the calls to the 3 deployment scripts.

In the /ado/infra/central/ado-agents/dockeragent directory, you can see the Dockerfile & startup script that the containers are built with. These are pulled from the Azure DevOps documentation with some additional code to download & unzip the appropriate ADO build agent code. They are not built locally on the build agent when this pipeline runs but are built inside the Azure Container Registry using the az acr build task (in the /ado/global/build-image.yml file).

You will also notice that ACI doesn’t require a Docker Compose or Kubernetes object YAML files. You can use YAML if you want to to configure, but you can also do the configuration directly in the deployment Bicep file /ado/infra/central/ado-agents/ado-build-agents/aci.bicep.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *