SSD Grow

How to Use Azure DevOps Build Agents That Are Self-Hosted

Azure DevOps has transformed the way development teams collaborate on code, integrate services, and automate deployment pipelines. One crucial aspect of Azure DevOps is the use of build agents, which run builds and deployment tasks. While Microsoft provides hosted agents for ease of use, self-hosted agents offer more control, customization, and flexibility. In this blog, we’ll explore how to set up and use self-hosted Azure DevOps build agents.

Build agents are responsible for running tasks in Azure Pipelines, such as compiling code, running tests, or deploying to environments. In Azure DevOps, there are two kinds of agents:

  • Microsoft-hosted agents: Pre-configured virtual machines provided by Microsoft that are ready to use for different tasks.
  • Self-hosted agents: Custom-built machines that you configure and manage yourself.

Self-hosted agents can be particularly beneficial when you require specific configurations or have sensitive environments that shouldn’t run on public, cloud-hosted resources.

Why Use Self-Hosted Build Agents in Azure DevOps?

Using self-hosted build agents in Azure DevOps comes with several advantages:

  1. Customization: You can install any specific software, SDKs, or tools required for your build process.
  2. Performance: Self-hosted agents allow for more powerful hardware, tailored to your requirements, which can speed up the build process.
  3. Control: You maintain full control over the machine, security, and the environment.
  4. Cost-Effectiveness: If you’re running many builds, self-hosted agents could reduce costs, especially if you already have spare infrastructure.

How to Set Up a Self-Hosted Azure DevOps Build Agent

Setting up self-hosted build agents in Azure DevOps is a straightforward process. Here’s a step-by-step guide:

Step 1: Create a Personal Access Token (PAT)

Before setting up the agent, you’ll need a Personal Access Token (PAT) to authenticate the agent with Azure DevOps.

  1. Navigate to your Azure DevOps account.
  2. Select User Settings in the upper-right corner and then select Personal Access Tokens.
  3. Click New Token, give it a descriptive name, and set the scope to Agent Pools (Read & Manage).
  4. Generate the token and keep it safe, as it will be used to authenticate the agent.

Step 2: Download and Configure the Agent

  1. Navigate to Pipelines in Azure DevOps, and then click on Agent Pools.
  2. Click New Agent and select your operating system.
  3. Download the agent package and extract it on the machine where you want to install the agent.
  4. To access the extracted folder, launch a terminal and go there.
  5. Run the command config.cmd (for Windows) or ./config.sh (for Linux) and follow the prompts.
    • Enter the Azure DevOps URL.
    • Paste the Personal Access Token when prompted.
    • Choose whether to run the agent as a service or interactively.
  6. Once configured, run the agent using run.cmd (for Windows) or ./svc.sh install (for Linux).

Step 3: Link the Agent to a Pipeline

Once the agent is configured and running, you need to assign it to a pipeline.

  1. Navigate to your pipeline in Azure DevOps.
  2. Select Agent Pool from the Pipeline section.
  3. Choose your self-hosted agent pool, and your pipeline will now run on the self-hosted agent.

Best Practices for Managing Self-Hosted Agents

Using self-hosted agents in Azure DevOps offers flexibility, but it’s essential to manage them effectively to get the most out of your setup.

  1. Security: Ensure your self-hosted agent machines are properly secured, especially when dealing with sensitive environments. Limit access to the machine and secure it with firewalls and proper authentication mechanisms.
  2. Agent Updates: Regularly update the agent software to take advantage of new features and security patches.
  3. Resource Management: Monitor the resource utilization of your self-hosted agents to ensure they are running optimally. Overloaded agents can slow down builds.
  4. Agent Pools: Set up multiple self-hosted agents in a pool if you need parallel builds or have high availability requirements.

Conclusion

Self-hosted build agents in Azure DevOps offer a high level of control, customization, and performance, making them ideal for teams with specific build requirements or sensitive environments. By setting up self-hosted agents, you can optimize your CI/CD pipeline, leverage powerful hardware, and maintain security on your own terms. With proper management and maintenance, such as regular updates, monitoring, and secure configurations, self-hosted agents can greatly enhance your development process while offering cost-saving benefits. Take control of your build infrastructure and unlock the full potential of Azure DevOps with self-hosted agents.

Related Articles