How to configure Self Hosted Agent for Azure Pipelines

How to configure Self Hosted Agent for Azure Pipelines

Table of contents

No heading

No headings in the article.

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:-

  1. Microsoft-hosted agents:- This is a service totally managed by Microsoft and are available for use in Azure Pipelines at no extra cost.

  2. 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 - dev.azure.com

2. Select your project dashboard

3. Go to your project settings

4. Click on Agent pools

s

  • 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

    1. 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 vstsagentpackage.azureedge.net/agent/2.214...

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:

./config.sh

Accept the Team Explorer Everywhere license agreement now?

Type Y and enter

Step #5:

Enter server URL >
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

./runsvc.sh

This confirms that Build agent is successfully configured in Azure DevOps and is available to run builds.