2

Setup Self Hosted Linux Agent in Azure DevOps

 7 months ago
source link: https://microsoftgeek.com/?p=3418
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Setup Self Hosted Linux Agent in Azure DevOps

Let us learn how to create and configure a Self-Hosted Agent in Azure DevOps (ADO).

Screen%20Shot%202023-01-25%20at%2010.10.10%20PM.png

What is an Agent?

An agent is computing infrastructure with installed agent software that runs one job at a time.

To build your code or deploy your software using Azure Pipelines, you need at least one agent. As you add more code and people, you’ll eventually need more.

When your pipeline runs, the system begins one or more jobs. 

In Azure pipelines, there are two types of build agents:

  1. Microsoft-hosted agents – This is a service totally managed by Microsoft and it’s cleared on every execution of the pipeline (on each pipeline execution, you have a fresh new environment).
  2. Self-hosted agents – This is a service that you can to set up and manage by yourself. This can be a custom virtual machine on Azure or a custom on-premise machine inside your infrastructure. 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 18.0.4) 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

Screen%20Shot%202023-01-11%20at%2010.59.57%20PM.png

4. Click on Agent pools

Screen%20Shot%202023-01-11%20at%2011.00.21%20PM.png

Create a new Agent pool name

Screen%20Shot%202023-01-22%20at%209.01.27%20PM.png

Enter name as Ubuntu18-VM-Pool or any name

Make sure you select Grant access permission to all pipelines

Screen%20Shot%202023-01-22%20at%209.03.09%20PM.png

click on Ubuntu18-VM-Pool, Agents, New agent

Screen%20Shot%202023-01-22%20at%209.05.34%20PM.png

Click on Linux

Screen%20Shot%202023-01-16%20at%209.51.07%20PM.png

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

Screen%20Shot%202023-01-22%20at%208.17.26%20PM.png

Step #3 – Configure the Agent

tar zxvf vsts-agent-linux-x64-2.214.1.tar.gz

Screen%20Shot%202023-01-22%20at%208.20.37%20PM.png

List the files in the directory after extracting.

ls -al

Screen%20Shot%202023-01-22%20at%208.22.18%20PM.png

Step #4:

Run the below command:

./config.sh

Screen%20Shot%202023-01-17%20at%2010.10.45%20PM.png

Accept the Team Explorer Everywhere license agreement now?

Type Y and enter

Screen%20Shot%202023-01-16%20at%2010.07.14%20PM.png

Step #5:

Enter server URL >
https://dev.azure.com/yourorganization

Step #6:

Enter authentication type (press enter for PAT) > PAT

Step #7:

Enter personal access token, generated from this step

Step #8:

Enter Agent pool

Give some name

Step #9:

Enter Agent name –> myBuildAgent_1

Step #10:

Enter work folder > enter

Screen%20Shot%202023-01-16%20at%2010.35.02%20PM.png

that’s it agent is successfully configured.

Configure the Agent to run as a Service

sudo ./svc.sh install &

Execute now to run as a service

./runsvc.sh &

Screen%20Shot%202023-01-16%20at%2010.58.44%20PM.png

Check the status of build Agent

Click on Ubuntu-18-VM pool name

Click on Agents

Screen%20Shot%202023-01-23%20at%209.12.38%20PM.png

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

Steps for removing Agent from the agent pool

Remove the service first

sudo ./svc.sh uninstall

Screen%20Shot%202023-01-22%20at%208.54.45%20PM.png

./config.sh remove

Screen%20Shot%202023-01-22%20at%208.56.29%20PM.png

To Perform Java related builds on this Agent, make sure you install Java and Maven on this VM.

Install Java 11

sudo apt-get install default-jdk -y

Maven Installation
Maven is a popular build tool used for building Java applications. You can install Maven by executing below command:

sudo apt update && sudo apt install maven -y

Check if Maven got installed

mvn –version


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK