Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Contact
  • Reviews
  • Toggle search form
Home » Automation » How to Create Self-Hosted Agent for Azure DevOps Pipelines

How to Create Self-Hosted Agent for Azure DevOps Pipelines

Posted on 30/01/202406/12/2024 Imoh Etuk By Imoh Etuk No Comments on How to Create Self-Hosted Agent for Azure DevOps Pipelines
ADO-Self-hosted-agent

Azure DevOps Pipelines offer a powerful and flexible way to automate your software development workflows. You can create and configure self-hosted agents to enhance your flexibility and control over your build and deployment processes. This article will walk us through the steps to create a self-hosted agent for Azure DevOps Pipelines. You may also be interested in the following articles: how to run your first Pipelines using Azure DevOps and how to configure email notifications in Azure DevOps. See also How to Integrate SonarCloud with Azure DevOps Pipeline

Self-hosted agents allow you to run your builds on your infrastructure, providing customization and scalability as opposed to Microsoft-hosted agents.

Please see how to set up a self-hosted speed test server on Ubuntu Linux, and Veeam Agent Vulnerability: Fix Veeam Agent vulnerability for Microsoft Windows.

Prerequisites for Creating a Self-Hosted Agent

Azure DevOps Account: Ensure you have an active Azure DevOps account. If not, sign up for one at Azure DevOps.

Azure DevOps Organization: This is where your project is being held.
Azure DevOps Project: Create or have an existing project within your Azure DevOps account.

Create a Self-Hosted Agent for Azure DevOps Pipelines

To create a self-hosted agent, do the following: Please see how to Remove the Bing Chat Button from the Edge Sidebar, and how to migrate the Veeam Configuration Database to PostgreSQL Server.

Step 1: Create a Personal Access Token (PAT)

On your Azure DevOps account, locate the User Settings icon on the right side of the screen, ensuring that the Azure DevOps organization you want to create the token is highlighted. As shown below, we are creating the token for Org-AB’s Azure DevOps organization.

1-Click-on-PAT
Creating a Personal Access Token

Next, click on PAT from the drop-down menu.

1-Create-a-PAT
Selecting PAT

When the next screen opens up, click on “New Token.” Ensure that you select the personal access tokens under the Security tab.

3-new-Pat
Creating a New Token

Enter the name for the token and expiration date, custom-defined, and then click on “Show all scopes” to display the agent pools tab. Then select read and manage access right for the agent pool.

5-select-agent-pool-and-read-and-manage-access
Entering the details for creating the token

Finally, copy the token to a notepad editor for future use. Please see Veeam Backup Deployment options for Microsoft 365 Data.

6-copy-the-token
Copy out the token

Step 2: Create Agent Pool

To create an agent pool from Azure DevOps organization settings, scroll to Agent Pools under the Pipelines tab. Click on Add Pool.

7-Create-agent-pool
Adding a pool

From the add pool screen, select self-hosted, provide the agent pool name; the description is optional, and then click on Create. 

Keep the auto-provision this agent in all the projects within the organization checked if you want to use the same token across all projects
8-click-on-self-hosted
9-create-agent-pool

You should see the newly created agent pool in the list of agent pools now.

9-agent-shows-in-the-pool-list
Newly created agent pool

Step 3: Create a new agent

The next step is to create a new agent within the agent pool created in the previous step. To do so, double-click on the name of the agent pool and click on “New agent.”

10-create-a-new-agent
Creating a New Agent

From the above screen, under the Windows OS tab, click on download.

Note, we're selecting Windows because we want to create the agent for Windows OS. If you're using macOS or Linux OS, enure to select the appropriate OS. 
12-downloading-agent
Downloading agent

Wait for the agent to finish downloading. We have already downloaded the agent, so I will cancel my download and use the already downloaded copy instead.

Step 4: Create an agent locally on your machine

To create an agent locally, launch PowerShell in administrative mode.

13-Launch-PowerShell-in-Admin-mode
Launching PowerShell in Admin Mode

On the PowerShell screen, run:

PS C:\> mkdir agent ; cd agent

PS C:\agent> Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$HOME\Downloads\vsts-agent-win-x64-3.232.3.zip", "$PWD")
14-run-commands-to-extract-the-agent-file
Extracting the Agent Files

The above command creates a directory called agent, navigates into the directory, and then extracts the agent files into the agent directory.

Step 5: Configure the agent

To configure the agent, run:

# This command configures the agent on your local machine
.\config.cmd
15-configuring-the-agent
Configuring agent on the local machine

Let me explain a few things from the above screenshot.

The server URL is the URL for your Azure DevOps Organization. The personal access token is the one we created in step 1. The name of the agent pool is the one we created in step 2. We specify the name of the agent as "techdirectarchive_agent" the next steps in the configuration process involve, pressing the Enter key and Y and on the last step, we press Enter for N and our agent was successfully started. 

The agent won’t run until we run it. It shows offline in the Azure DevOps organization.

16-Agent-Status-on-ADO
Agent status

Step 6: Run the Agent locally

To run the agent, type the command below and press the Enter key.

.\run.cmd
17-agent-running
Running agent

Checking the Azure DevOps organization now, the agent status is reporting “Online.”

19-agent-shows-online
Agent status reporting online

One good thing about running a self-hosted agent is that you have the flexibility to start and stop it whenever you like. Which means you’re in control of everything.

Run Azure DevOps Pipelines using Self-Hosted Agent

After creating the self-hosted agent, let us use it to run pipelines for our application.

We will go through the following steps to get this done:

Step 1: Get the Application Sample Code from GitHub

The above GitHub repository is provided by Microsoft for demo purposes.

1-Prepare-Project
Preparing Azure DevOps Project

Step 2: Prepare the Azure DevOps Project

Here we will import the application codes from GitHub into the Azure Repo.

2-clone-sample-codes-from-GitHUb
Importing Codes from GitHub

The below screenshot shows that the codes have been imported successfully:

3-code-imported
Code Imported Successfully

Step 3: Create a Build Pipeline

The next step is to create a build pipeline. To do so, navigate to the Pipelines tab in your Azure DevOps project. Click on Create Pipeline.

4-Create-a-Pipeline
Creating a Build Pipeline

On the next screen, select where your code is stored as an Azure Repos Git.

5-Select-code-repo
Build Pipeline setup process

When asked to select a repository, click on the name of your Azure DevOps project.

6-code-repo
Select Code Repository

In the configure your pipeline screen, select ASP.NET Core (.Net Framework).

7-Cofigure-your-Pipeline
Configuring Build Pipeline

Review the YAML (Yet Another Markup Language) file before you save and run your pipeline. In the YAML file, we are going to make some modifications by replacing the vmImage: ‘windows-latest’ with the self-hosted agent created previously.

8-Reviewing-Pipeline
Reviewing the Pipeline file

Now replace the vmImage text with the below codes:

pool
  Name: my-agent-pool
demands:
- Agent.Name equals techdirectarchive_agent

Remember to replace the name of the agent pool and agent name with your own. After that, click Save and run.

9-Modifying-Pipeline-file-1
Modifying the pipeline file

This triggers the build automatically based on the pipeline configurations as soon as you add the commit message.

10-Add-commit-message
Adding commit message

The next screen should report the status of your build pipeline as successful, and you should also get an email notification.

Build-Pipeline-succeeded-1
Build-pipeline succeed

I hope you found this article useful on how to create a self-hosted agent for Azure DevOps pipelines. Please feel free to leave a comment below.

5/5 - (1 vote)

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
Automation, AWS/Azure/OpenShift, Version Control System, Windows Tags:Azure, Azure DevOps, Azure Pipelines, PowerShell

Post navigation

Previous Post: How to Permit a Blocked File or App in Windows Security Manually
Next Post: How to Remove Bing Chat Button from Edge Sidebar

Related Posts

  • screenshot 2020 02 07 at 21.56.50
    Setup Kiosk Mode on Windows 10 with AD User Account Windows
  • Allow and Disallow Simultaneous Connection to Domain and Non Domain network
    Allow and Disallow Simultaneous Connection to Domain and Non-Domain network Network | Monitoring
  • fddd
    How to check the version of Windows ADK Windows
  • PXE Boot to Install OS HyperV
    Run Hype-V on Windows 11 and Install Windows OS via PXE Boot Windows
  • Capture 2
    MDT Invalid credentials: The network was not found Windows
  • Lets Encryp
    How to install Let’s Encrypt Certificates with IIS on a Windows Server Windows

More Related Articles

screenshot 2020 02 07 at 21.56.50 Setup Kiosk Mode on Windows 10 with AD User Account Windows
Allow and Disallow Simultaneous Connection to Domain and Non Domain network Allow and Disallow Simultaneous Connection to Domain and Non-Domain network Network | Monitoring
fddd How to check the version of Windows ADK Windows
PXE Boot to Install OS HyperV Run Hype-V on Windows 11 and Install Windows OS via PXE Boot Windows
Capture 2 MDT Invalid credentials: The network was not found Windows
Lets Encryp How to install Let’s Encrypt Certificates with IIS on a Windows Server Windows

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

Veeam Vanguard

  • SUID GUID Sticky Bit 1
    Set Special File Permissions with SUID or GUID and Sticky Bit Linux
  • PersonalHow to Create Symbolic Links in Linux
    All You Need to Know About Symbolic Links in Linux Linux
  • Embed Microsoft Forms into Your Website Page
    How to Embed Microsoft Forms into Your Website Page Microsoft Exchange/Office/365
  • image 23
    Copy Deployment Share between Servers without using linked Deployment Shares Windows
  • Distributed File System DFS
    How to find Dfs Referral Path and clear Dfs referral Cache Storage
  • Azure backup for MSSQL
    Restore MSSQL Server on Azure VMs using Azure Backup Network | Monitoring
  • windows 10 technical preview windows 10 logo microsoft 97543 1920x1080
    Windows Editions: Various Operating Systems available for Windows Windows
  • Screenshot 2020 06 22 at 22.46.00
    How to use a dedicated MsSQL Db for Pleasant Password Oracle/MSSQL/MySQL

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,819 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

Active Directory Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.