Building Apps Using Self-Hosted Build Agents in Azure Pipelines

45 minutes
  • 4 Learning Objectives

About this Hands-on Lab

In this hands-on lab, you will be installing the build agent on a self-hosted Windows server, and then using that self-hosted build agent inside of a build pipeline. This process is an alternative to using Microsoft-hosted build agents and allows you to customize your build agent to your specific needs.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a New Azure DevOps Organization
  1. Login to the Azure portal, click on All services and select Azure DevOps.
  2. Click on the My Azure DevOps Organizations link (this will open a new tab).
  3. Once the fields have auto-populated with the name, email, and location, click Continue.
  4. Under Get started with Azure DevOps, click the Create new organization button.
  5. If prompted to agree to the terms of service, click the Continue button.
  6. Choose a name for your new DevOps Organization (the default will suffice).
  7. Choose the location Central US for the region to host your projects in and click Continue.
  8. On the project creation screen, type in "Application" for the project name.
  9. Set the visibility to Public.
  10. Click Create project.
Log in to the Windows Server and Install the Agent
  1. Go to the Azure Portal and click Virtual Machines.
  2. Select the VM and click Connect.
  3. Download the RDP file and log in to the server with the credentials azureuserLA!2019!Lab.
  4. Open Internet Explorer and go to
  5. Select your organization name, followed by the project name.
  6. Go to Project settings > Agent pools > Default.
  7. Select New agent, click on the Download button, and click Save.
  8. Once the file has been downloaded, from PowerShell run the command:
    mkdir agent ; cd agent
  9. From PowerShell, run the following command, replacing <FILE_NAME> with the name of the vsts file you downloaded (e.g.,
    Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$HOMEDownloads<FILE_NAME>", "$PWD")
  10. Type in the server URL ([your-organization-name]).
  11. Press Enter to accept PAT as the authentication type.
  12. Create a PAT from the DevOps Organization by clicking on the avatar in the upper right and selecting Personal access tokens.
  13. Name the token "agent", select Full access, and click Create.
  14. Copy the token and paste it into PowerShell.
  15. Press Enter to accept the defaults for agent pool, agent name, and work folder.
  16. Enter Y to run the agent as a service and enter the server credentials azureuserLA!2019!Lab.
Import the Code Repository into Azure Repos
  1. From the DevOps Project, go to Azure Repos and select Import.
  2. Enter the following repository:
  3. Click Import.
Create and Run the Build Pipeline
  1. From the DevOps Project, click on Azure Pipelines.
  2. Click New Pipeline.
  3. Select Azure Repos Git.
  4. Select the Application repository.
  5. Select the ASP.NET pipeline template.
  6. Change the YAML under pool to:
    name: Default
  7. Click on Save and run.
  8. Click on Save and run again.
  9. View the logs to see the correct build agent being used and wait for the build to complete.
  10. Click on Project settings > Agent pools > Default > Agents to see the job attached to the agent.

Additional Resources

Once logged in to the Azure Portal, you will create a new DevOps Organization by going to All Services > Azure DevOps. You will then log in to the Windows Server provided to you with the hands-on lab by going to Virtual Machines > Connect and downloading the RDP file. Once connected to the VM, you will open up Internet Explorer and go to and log in with the Azure credentials provided with the hands-on lab. Proceed to download and install the agent after creating a new DevOps project. Once you have installed the agent, you will be able to view the agent in the agent pools menu. Proceed to create a new pipeline and enter name: Default below pool in the YAML. Finally, run the build and verify the build is using the self-hosted build agent.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?