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. In the search bar at the top of the page, type devops and select Azure Devops organizations.
  2. Click My Azure DevOps Organizations.
  3. Once the fields have auto-populated, click Continue.
  4. Click Create new organization.
  5. If prompted to agree to the terms of service, click Continue.
  6. Leave the default region and organization name, complete the CAPTCHA at the bottom, and click Continue.
  7. On the Create a project to get started page under Visibility, click the organization policies link.
  8. Under Policies, scroll down to Security policies and toggle on Allow public projects.
  9. In the Change policy setting window, click Save.
  10. Navigate back to the project page.
  11. Under Project name, type application.
  12. Under Visibility, select Public and click + Create project.
Log In to the Windows Server and Install the Agent
  1. Return to the main Azure portal page and navigate to Virtual machines.

  2. Select the provisioned virtual machine.

  3. In Overview, click Connect > RDP.

  4. Click Download RDP File.

  5. Download the RDP file and log in to the server using the VM credentials provided on the lab page.

  6. Navigate to

    Note: In the Azure VM, we strongly recommend downloading, installing, and using Google Chrome instead of the default Internet Explorer browser.

  7. Sign in using the Azure portal credentials provided on the lab page.

  8. Select your organization name.

  9. Select the application project.

  10. At the bottom of the left menu, select Project settings.

  11. Under Pipelines select Agent pools and click Default.

  12. At the top right, click New agent.

  13. Under Download the agent, click Download

  14. From the Windows Start menu search bar, type powershell.

  15. Right-click on Windows PowerShell ISE and click Run as administrator.

  16. In PowerShell, create and navigate into the agent directory:

    mkdir agent ; cd agent
  17. Create the agent, 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")
  18. To configure the agent, run the .config.cmd file:

  19. Type in the server URL, replacing <YOUR_ORGANIZATION_NAME> with your own, which you can get from the browser bar (copy everything before /application):<YOUR_ORGANIZATION_NAME>
  20. Press Enter to accept a personal access token (PAT) as the authentication type.

  21. To create a PAT from the DevOps organization, click on the human avatar in the upper right of the portal (Cloud Student …) and select Security > Personal access tokens.

  22. Click + New Token.

  23. In Name, type agent.

  24. Under Scopes, select Full access and click Create.

  25. Copy the agent token and paste it into PowerShell.

  26. To accept the defaults for agent pool, agent name, and work folder, press Enter.

  27. To run the agent as a service, enter Y and enter the VM credentials provided on the lab page.

  28. To verify configuration, return to the DevOps organization page and navigate to application > Settings > Agent pools Default.

  29. Select the Agents tab and view the agent pool status.

    You should see a green status icon indicating the pool is online.

Import the Code Repository into Azure Repos
  1. On the left menu, select Repos.
  2. Scroll down to Import a repository and click Import.
  3. Under Clone URL, paste in the following repository link:
  4. Click Import.
Create and Run the Build Pipeline
  1. On the left menu, click Pipelines.

  2. Click Create Pipeline.

  3. Select Azure Repos Git.

  4. Select the application repository.

  5. Select the ASP.NET pipeline template.

  6. In the YAML under pool, delete the vmImage line and replace it with the following:

      name: Default
  7. Click Save and run > Save and run.

    A status window will appear stating the pipeline needs permissions to access a resource before this run can continue.

  8. In the status window, click View > Permit > Permit.

  9. To verify our job ran on the selected agent once the build has run, click Project settings > Agent pools > Default > Agents.

  10. Click the listed agent to see the job attached to the 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?