Azure DevOps | Setting up self-hosted Build Agent

Azure DevOps | Setting up self-hosted Build Agent

Title: Azure DevOps | Setting up a Self-Hosted Build Agent

Introduction: Azure DevOps is a powerful platform that provides a wide range of tools and services for software development and delivery. One of the key features of Azure DevOps is the ability to run build and release pipelines to automate the build, test, and deployment processes. While Azure DevOps offers its own hosted build agents, there are scenarios where you might need to set up a self-hosted build agent to meet specific requirements. In this blog post, we will explore the process of setting up a self-hosted build agent in Azure DevOps.

Prerequisites: Before we dive into the setup process, there are a few prerequisites that you need to fulfill:

  1. An Azure DevOps account: You should have an active Azure DevOps account to access the necessary features and services.

  2. An Azure virtual machine or an on-premises machine: You will need a machine to host the self-hosted build agent. It can be a virtual machine in Azure or a physical machine in your on-premises environment.

Step 1: Create a Personal Access Token (PAT) To authorize the self-hosted build agent to communicate with Azure DevOps, you need to create a Personal Access Token. Follow these steps to create a PAT:

  1. Go to your Azure DevOps account and navigate to the "User Settings" page.

  2. Click on "Personal Access Tokens" and then "New Token."

  3. Provide a name for your token, choose the desired organization, and select the appropriate scope for the token (e.g., Agent Pools, Build, and Read).

  4. Click on "Create" and make a note of the generated token. You will need it during the agent setup.

Step 2: Download and Configure the Build Agent Next, you need to download and configure the self-hosted build agent on your machine:

  1. Open the Azure DevOps portal and navigate to the "Agent Pools" page.

  2. Click on "New Agent" to download the agent package.

  3. Extract the downloaded package on your machine.

  4. Open a terminal or command prompt and navigate to the extracted agent folder.

  5. Run the configuration script using the following command:

     ./config.cmd
    
  6. Provide the requested information, such as the URL of your Azure DevOps organization and the PAT you generated earlier.

  7. Select the agent pool where you want to register the agent.

  8. Choose a unique name for the agent and specify any additional configuration options as needed.

  9. Save the provided settings, and the agent will be configured and registered with Azure DevOps.

Step 3: Start the Build Agent Once the agent is configured and registered, you need to start it to make it available for running build and release pipelines:

  1. In the terminal or command prompt, navigate to the agent folder.

  2. Run the following command to start the agent:

     ./run.cmd
    
  3. The agent will start and establish a connection with Azure DevOps.

  4. You can verify the agent's status in the Azure DevOps portal under the corresponding agent pool.

Step 4: Configure Pipelines to Use the Self-Hosted Agent Now that the self-hosted build agent is up and running, you can configure your pipelines to utilize it:

  1. Open your Azure DevOps project and navigate to the pipeline that you want to modify.

  2. Edit the pipeline configuration and find the agent specification.

  3. Change the agent specification to specify the agent pool and agent name that you set up in Step 2.

  4. Save the pipeline changes, and it will now utilize the self-hosted build agent for its execution.

Conclusion: Setting up a self-host