Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Automation » How to Create Self-Hosted Agent for Azure DevOps Pipelines
  • 41592 3264bitw10
    What is the difference between 32-bit and 64-bit processors Windows Server
  • Featured image Audioissue
    How to Fix Audio Services Not Responding on Windows 10 and 11 Windows
  • macos12
    Enable or disable automatic login on macOS: Fix username greyed out for automatic login Mac
  • 05kvj2jzbpj1ugp4etb4gdf 19.fit scale.size 2698x1517 e1690630247655
    Various methods to launch the Event Viewer Windows Server
  • screenshot 2020 03 26 at 22.14.14
    How to create a scheduled task with Windows Admin Center Windows Server
  • Exchange password
    How to block the Change Password Feature for All Users via the Exchange Administrative Center Network | Monitoring
  • Cannot Start Proctored Exam
    DbxSvc Process: How to Fix “Cannot Start Proctored Exam” Windows
  • PowerShell Exec
    Determine the execution policy configured on Windows PC Windows

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.

  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on Threads (Opens in new window) Threads
  • Click to 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

  • Featured image Teams Whiteboard
    How to use Whiteboard in Microsoft Teams meetings Windows
  • image 12
    How to Use Postman with the Amazon Pinpoint API AWS/Azure/OpenShift
  • MBRGPT
    Run MBR and GPT conversion with the best GPT converter Windows
  • jmeterlogo 3
    Install and conduct performance testing using Apache JMeter on your Web App Configuration Management Tool
  • Screenshot 2020 05 13 at 19.23.25
    AWS Command-Line Interface: How to configure AWS CLI [Part 1] AWS/Azure/OpenShift
  • fghj
    Windows Profile: How to determine your windows username Windows

More Related Articles

Featured image Teams Whiteboard How to use Whiteboard in Microsoft Teams meetings Windows
image 12 How to Use Postman with the Amazon Pinpoint API AWS/Azure/OpenShift
MBRGPT Run MBR and GPT conversion with the best GPT converter Windows
jmeterlogo 3 Install and conduct performance testing using Apache JMeter on your Web App Configuration Management Tool
Screenshot 2020 05 13 at 19.23.25 AWS Command-Line Interface: How to configure AWS CLI [Part 1] AWS/Azure/OpenShift
fghj Windows Profile: How to determine your windows username 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

sysadmin top30a

  • 41592 3264bitw10
    What is the difference between 32-bit and 64-bit processors Windows Server
  • Featured image Audioissue
    How to Fix Audio Services Not Responding on Windows 10 and 11 Windows
  • macos12
    Enable or disable automatic login on macOS: Fix username greyed out for automatic login Mac
  • 05kvj2jzbpj1ugp4etb4gdf 19.fit scale.size 2698x1517 e1690630247655
    Various methods to launch the Event Viewer Windows Server
  • screenshot 2020 03 26 at 22.14.14
    How to create a scheduled task with Windows Admin Center Windows Server
  • Exchange password
    How to block the Change Password Feature for All Users via the Exchange Administrative Center Network | Monitoring
  • Cannot Start Proctored Exam
    DbxSvc Process: How to Fix “Cannot Start Proctored Exam” Windows
  • PowerShell Exec
    Determine the execution policy configured on Windows PC Windows

Subscribe to Blog via Email

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

Join 1,839 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

AWS 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.