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. An agent is computing infrastructure with installed agent software that runs one job at a time.
Azure Pipelines provides several different types of agents.
- Microsoft-hosted agents (Agents hosted and managed by Microsoft).
- Self-hosted agents (Agents that you configure and manage, hosted on your VMs).
- Azure Virtual Machine Scale Set agents (A form of self-hosted agents, using Azure Virtual Machine Scale Sets, that can be auto-scaled to meet demands).
In this document, we will cover how to set up a self-hosted runner on an Ubuntu machine, configuring it to run as a systemd service.
Prerequisites:
- Microsoft Account: Ensure you have a Microsoft account set up.
- Azure Account and Subscription: Set up your Azure account and ensure you have an active subscription.
- Azure Virtual Machine: Create a VM running Ubuntu 22.04 in the Azure Cloud.
- Personal Access Token: Generate a Personal Access Token (PAT) in Azure DevOps.
Steps to Configure Self Hosted in Ubuntu Machine
In your web browser, navigate to Agent pools:
- Sign in to your organization (https://dev.azure.com/{yourorganization}).
- Choose Azure DevOps, Organization settings.
- Choose Agent pools.
- ADD a new Agent pool (Click on ADD Pool and then select Self Hosted)
- Setup a New Agent
- Click on Linux (As we are using Linux Machine), and then copy the URL to download the agent in your Ubuntu Machine.
Login to your Azure VM and then execute these following commands to download and setup your agent
- mkdir myagent && cd myagent
- wget https://vstsagentpackage.azureedge.net/agent/3.242.1/vsts-agent-linux-x64-3.242.1.tar.gz
- tar zxvf vsts-agent-linux-x64-3.242.1.tar.gz
- ./config.sh
Note : Configure your Agent by Answering these following questions
"Enter server URL" > https://dev.azure.com/{yourorganization}/
"Enter authentication type (press enter for PAT)" >
"Enter personal access token" >
"Enter agent pool (press enter for default)" >
"Enter agent name (press enter for AZDevops-test-runner)" >
Configure the Agent to run as a Service
- sudo ./svc.sh install &
- ./runsvc.sh &
- Now Follow these steps to run this service as a systemd service
- Create a file called /etc/systemd/system/MyTestAgent.service
[Unit]
Description=Runner_AD
After=network.target
StartLimitIntervalSec=0
[Service]
#User=root
User=azureuser
#Restart=on-failure
ExecStart=/home/azureuser/myagent/runsvc.sh
StandardOutput=syslog
StandardError=syslog
#Change this to find app logs in /var/log/syslog
SyslogIdentifier=adrunner
[Install]
WantedBy=multi-user.target
- Your runsvc.sh should look like this (Make the changes accordingly)
#!/bin/bash
# convert SIGTERM signal to SIGINT
# for more info on how to propagate SIGTERM to a child process see: http://veithen.github.io/2014/11/16/sigterm-propagation.html
trap 'kill -INT $PID' TERM INT
if [ -f ".path" ]; then
# configure
export PATH=`cat .path`
echo ".path=${PATH}"
fi
# insert anything to setup env when running as a service
# fallback on Node16 if Node20 is not supported by the host
./externals/node20_1/bin/node --version
if [ $? == 0 ]; then
NODE_VER="node20_1"
else
NODE_VER="node16"
fi
# run the host process which keep the listener alive
./externals/"$NODE_VER"/bin/node ./bin/AgentService.js &
PID=$!
wait $PID
trap - TERM INT
wait $PID
- sudo systemctl daemon-reload
- sudo systemctl enable MyTestAgent.service
- sudo systemctl start MyTestAgent.service
- sudo systemctl status MyTestAgent.service
Voila! We have successfully Configured & Setup Azure DevOps Self Hosted Linux Runner as a Systemd service.
Top comments (0)