- Lab
- A Cloud Guru
Building Apps Using Self-Hosted Build Agents in Azure Pipelines
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.
Path Info
Table of Contents
-
Challenge
Create a New Azure DevOps Organization
- In the search bar at the top of the page, type devops and select Azure Devops organizations.
- Click My Azure DevOps Organizations.
- Once the fields have auto-populated, click Continue.
- Click Create new organization.
- If prompted to agree to the terms of service, click Continue.
- Leave the default region and organization name, complete the CAPTCHA at the bottom, and click Continue.
- On the Create a project to get started page under Visibility, click the organization policies link.
- Under Policies, scroll down to Security policies and toggle on Allow public projects.
- In the Change policy setting window, click Save.
- Navigate back to the project page.
- Under Project name, type application.
- Under Visibility, select Public and click + Create project.
-
Challenge
Log In to the Windows Server and Install the Agent
-
Return to the main Azure portal page and navigate to Virtual machines.
-
Select the provisioned virtual machine.
-
In Overview, click Connect > RDP.
-
Click Download RDP File.
-
Download the RDP file and log in to the server using the VM credentials provided on the lab page.
-
Navigate to https://aex.dev.azure.com.
Note: In the Azure VM, we strongly recommend downloading, installing, and using Google Chrome instead of the default Internet Explorer browser.
-
Sign in using the Azure portal credentials provided on the lab page.
-
Select your organization name.
-
Select the application project.
-
At the bottom of the left menu, select Project settings.
-
Under Pipelines select Agent pools and click Default.
-
At the top right, click New agent.
-
Under Download the agent, click Download
-
From the Windows Start menu search bar, type powershell.
-
Right-click on Windows PowerShell ISE and click Run as administrator.
-
In PowerShell, create and navigate into the
agent
directory:mkdir agent ; cd agent
-
Create the agent, replacing
<FILE_NAME>
with the name of thevsts
file you downloaded (e.g.,vsts-agent-win-x64-2.175.2.zip
):Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$HOME\Downloads\<FILE_NAME>", "$PWD")
-
To configure the agent, run the
.\config.cmd
file:.\config.cmd
-
Type in the server URL, replacing
<YOUR_ORGANIZATION_NAME>
with your own, which you can get from the browser bar (copy everything before /application):https://dev.azure.com/<YOUR_ORGANIZATION_NAME>
-
Press Enter to accept a personal access token (PAT) as the authentication type.
-
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.
-
Click + New Token.
-
In Name, type agent.
-
Under Scopes, select Full access and click Create.
-
Copy the agent token and paste it into PowerShell.
-
To accept the defaults for
agent pool
,agent name
, andwork folder
, press Enter. -
To run the agent as a service, enter
Y
and enter the VM credentials provided on the lab page. -
To verify configuration, return to the DevOps organization page and navigate to application > Settings > Agent pools Default.
-
Select the Agents tab and view the agent pool status.
You should see a green status icon indicating the pool is online.
-
-
Challenge
Import the Code Repository into Azure Repos
- On the left menu, select Repos.
- Scroll down to Import a repository and click Import.
- Under Clone URL, paste in the following repository link: https://github.com/chadmcrowell/devops-asp-build
- Click Import.
-
Challenge
Create and Run the Build Pipeline
-
On the left menu, click Pipelines.
-
Click Create Pipeline.
-
Select Azure Repos Git.
-
Select the application repository.
-
Select the ASP.NET pipeline template.
-
In the YAML under
pool
, delete thevmImage
line and replace it with the following:pool: name: Default
-
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.
-
In the status window, click View > Permit > Permit.
-
To verify our job ran on the selected agent once the build has run, click Project settings > Agent pools > Default > Agents.
-
Click the listed agent to see the job attached to the agent.
-
What's a lab?
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.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.