Skip to main content

Building Apps Using Self-Hosted Build Agents in Azure Pipelines

Hands-On Lab

 

Photo of Chad Crowell

Chad Crowell

DevOps Training Architect II in Content

Length

00:45:00

Difficulty

Intermediate

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.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Building Apps Using Self-Hosted Build Agents in Azure Pipelines

Introduction

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.

Solution

Log in to the Azure Portal using the credentials provided on the lab instructions page.

Create a New Azure DevOps Organization

  1. 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.
  8. Click Continue.
  9. On the project creation screen, type in "Application" for the project name.
  10. Set the visibility to Public.
  11. 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 following credentials:

    • Username: azureuser
    • Password: LA!2019!Lab
  4. Open Internet Explorer and go to https://aex.dev.azure.com.

  5. Sign in using the credentials provided on the lab page (the ones you used to sign in to the Azure Portal).

  6. Select your organization name, followed by the project name.

  7. Go to Project settings > Agent pools > Default.

  8. Select New agent, click on the Download button, and click Save.

  9. Once the file has been downloaded, open PowerShell and click Run as administrator.

  10. In PowerShell, run the command:

    mkdir agent ; cd agent
  11. Run the command:

    Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$HOMEDownloadsvsts-agent-win-x64-2.159.2.zip", "$PWD")
  12. Run the .config.cmd file:

    .config.cmd
  13. Type in the server URL, replacing <YOUR_ORGANIZATION_NAME> with yours, which you can get from the Internet Explore browser bar (everything up until /application):

    https://dev.azure.com/<YOUR_ORGANIZATION_NAME>
  14. Press Enter to accept PAT as the authentication type.

  15. Create a PAT from the DevOps Organization by clicking on the avatar in the upper right and selecting Personal access tokens.

  16. Name the token "agent", select Full access, and click Create.

  17. Copy the token and paste it into PowerShell.

  18. Press Enter to accept the defaults for agent pool, agent name, and work folder.

  19. Enter Y to run the agent as a service and enter the following credentials:

    • Username: azureuser
    • Password: LA!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: https://github.com/chadmcrowell/devops-asp-build.
  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:

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

  8. Click 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 Project settings > Agent pools > Default > Agents.

  11. Click the listed agent to see the job attached to the agent.

Conclusion

Congratulations on successfully completing this hands-on lab!