How to configure Self Hosted Agent for Azure Pipelines

Table of contents

What is an Agent ?
\=> An agent is computing infrastructure with installed agent software that runs one job at a time.
There are primarily two types of build agents in Azure Pipelines:-
Microsoft-hosted agents:- This is a service totally managed by Microsoft and are available for use in Azure Pipelines at no extra cost.
Self-hosted agents:- This is a service that you set up and manage on your own infrastructure, such as your on-premises servers or virtual machines in the cloud. In a self-hosted agent, you can install all the software you need for your builds, and this is persisted on every pipeline execution. A self-hosted agent can be on Windows, Linux, macOS, or in a Docker container.
Pre-requisites:-
Microsoft account setup
Azure account and subscription setup
Create a VM(Ubuntu 22.04) in Azure Cloud
Create Personal Access Token in Azure DevOps
How to configure Self-hosted build agent?
1. Go to Azure DevOps dashboard - https://dev.azure.com/
2. Select your project dashboard
3. Go to your project settings
4. Click on Agent pools
5. Create a new Agent pool name :-
Enter any name in my case, I have given "sami-hosted"
Make sure you select Grant access permission to all pipelines
6. click on sami-hosted Agents, New agent
Click on Linux
Note down the steps to configure Linux build agent.
Login to your Azure VM now.Step #1 - Create the Agent
mkdir myagent && cd myagent
Step #2 - Download the agent
wget https://vstsagentpackage.azureedge.net/agent/2.214.1/vsts-agent-linux-x64-2.214.1.tar.gz
Step #3 - Configure the Agent
tar zxvf vsts-agent-linux-x64-2.214.1.tar.gz
List the files in the directory after extracting.
ls -alh
Step #4:
Run the below command:
Accept the Team Explorer Everywhere license agreement now?
Type Y and enter
Step #5:
Enter server URL >
https://dev.azure.com/your-site-name
Enter authentication type (press enter for PAT) > PAT
Enter personal access token
Enter Agent pool
Give some name
Enter work folder > enter
Configure the Agent to run as a Service
sudo ./svc.sh install
Execute now to run as a service
This confirms that Build agent is successfully configured in Azure DevOps and is available to run builds.
Subscribe to my newsletter
Read articles from Samikshya Sapkota directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Samikshya Sapkota
Samikshya Sapkota
Learner