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.
Successfully complete this lab by achieving the following learning objectives:
- 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.
- 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
mkdir agent ; cd agent
Create the agent, replacing
<FILE_NAME>with the name of the
vstsfile you downloaded (e.g.,
Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$HOMEDownloads<FILE_NAME>", "$PWD")
To configure the agent, run the
Type in the server URL, replacing
<YOUR_ORGANIZATION_NAME>with your own, which you can get from the browser bar (copy everything before /application):
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 name, and
work folder, press Enter.
To run the agent as a service, enter
Yand 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.
- 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.
- 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 the
vmImageline 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.