While Azure DevOps have a generous free offering, running CI/CD pipelines with Azure Pipelines will require a paid plan to use Azure hosted runners, a cost effective solution would be to provision and configure your own runner.
If you're used to platforms like GitHub Actions or haven't worked with Jenkins, managing and configuring runners may feel unfamiliar. This rather brief piece aims to simplify the process and walk you through provisioning your own self-hosted agent for Azure Pipelines.
What is a Runner?
Although natively reffered to as "Agents" in the Azure ecosystem, the most common name for it would be "Runners".
When your pipeline runs, the system begins one or more jobs. A runner is a computing infrastructure that executes jobs defined in your continuous integration (CI) or continuous delivery (CD) pipelines. It’s the environment where tasks like building, testing, and deploying your application are carried out
Azure Devops offer other options for these "agents", there is the:
- Microsoft-hosted
- Self-hosted agents
- Azure Virtual Machine Scale Set agents
- Managed DevOps Pools agents
But we will focus on the Self-hosted agents as the other options might come at a pricey rate. You can learn more about the other options here.
Why Use Self-Hosted Runners?
As you can probably figure out by now, cost efficiency is just one of the many reasons to use self-hosted runners. Nearly all continuous integration platforms provide the option to utilize your own runners, and the benefits extend beyond saving money.
Here are some key advantages:
- Data Security and Compliance: Self-hosted runners allow you to maintain tighter control over sensitive data and meet specific compliance requirements.
- Faster Builds and Better Resource Management: With self-hosted runners, you can allocate resources according to your needs, leading to faster build times and greater flexibility in managing workloads.
- Support for Special Scenarios and Legacy Systems: They are particularly useful for handling unique setups or supporting older systems that may not be compatible with shared runners.
If you have stuck around for this long, you probably are ready to dive into configuring your own self-hosted agent for Azure Pipelines so let's begin.
Step-by-Step Guide to Setting Up a Self-Hosted Agent
I will be using an Azure Virtual Machine (cool sticking to the eco-system) as the infrastructure for our agent. But you can use any virtual machine and even your local system. But before if you are not running linux, you might have to select a few different options aling the line.
1 - Create a Virtual Machine
- Provision a virtual machine (VM) in Azure and ensure SSH access is enabled.
2 - Configure an Agent Pool in Azure DevOps
- Navigate to Organization Settings > Agent Pools.
- Click Add Pool, provide details, and select Grant access permission to all pipelines.
- Open the newly created pool, go to the Agents tab, and click New Agent.
3 - Install and Configure the Agent on the VM
- SSH into your virtual machine.
- Run the following commands to set up the agent:
# create a new directory, downloads the agent and unpacks the files
mkdir myagent && cd myagent
wget https://vstsagentpackage.azureedge.net/agent/4.248.0/vsts-agent-linux-x64-4.248.0.tar.gz
tar zxvf vsts-agent-linux-x64-4.248.0.tar.gz
# configure the agent
./config.sh
During configuration, you’ll be prompted for:
- Server URL: Use https://dev.azure.com/{yourorganization}.
- Personal Access Token (PAT): Generate this from User Settings > - - Personal Access Token in Azure DevOps.
- Agent Pool Name: Enter the name of your pool (if you did not use default).
- Agent Name and Work Folder: Confirm these settings.
At this point the agent status will appear as "offline" on the Azure Devops platform, Run:
./run.sh
After this, your agent should now be online and ready to accept jobs.
Final words
With your self-hosted agent set up, remember that you are responsible for maintaining it. This includes applying patches, updates, and installing tools as needed. For example, if your pipeline requires Docker, you’ll need to install and configure Docker on the VM.
By following these steps, you now have a cost-effective and flexible agent for Azure Pipelines.
Keep building!
Top comments (0)