You are currently viewing How to install configure and add self-hosted agents in Azure DevOps?

How to install configure and add self-hosted agents in Azure DevOps?

How to install, configure and add self-hosted agent in Azure DevOps?

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

Today we are going to discuss how to install configure and add a self-hosted agent in Azure DevOps.

What is Azure Pipeline?

Azure Pipelines automatically builds and tests code projects to make them available to others. It works with just about any language or project type. Azure Pipelines combines continuous integration (CI) and continuous delivery (CD) to test and build your code and ship it to any target.

What is Azure Pipelines agents?

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.

  • Microsoft-hosted agents: If your pipelines are in Azure Pipelines, then you’ve got a convenient option to run your jobs using a Microsoft-hosted agent. With Microsoft-hosted agents, maintenance and upgrades are taken care of for you. Each time you run a pipeline, you get a fresh virtual machine for each job in the pipeline. The virtual machine is discarded after one job. Microsoft-hosted agents can run jobs directly on the VM or in a container.
  • Self-hosted agents: An agent that you set up and manage on your own to run jobs is a self-hosted agent. You can use self-hosted agents in Azure Pipelines or Team Foundation Server (TFS). Self-hosted agents give you more control to install dependent software needed for your builds and deployments. Also, machine-level caches and configuration persist from run to run, which can boost speed.

What is Azure Pipelines agent pools?

Instead of managing each agent individually, you organize agents into agent pools. In Azure Pipelines, pools are scoped to the entire organization; so you can share the agent machines across projects. In Azure DevOps Server, agent pools are scoped to the entire server; so you can share the agent machines across projects and collections. When you configure an agent, it is registered with a single pool, and when you create a pipeline, you specify which pool the pipeline uses. When you run the pipeline, it runs on an agent from that pool that meets the demands of the pipeline.

Next, we are going to create a new agent pool and then install, configure and add a new self-hosted agent into our agent pool.

How to install, configure and add self-hosted agent in Azure DevOps?

Prerequisites:

  • One active Azure DevOps account
  • Personal Access Token (PAT)
  • One Linux instance where you will host the self-hosted agent. I am using an AWS EC2 instance with Amazon Linux 2 OS for this demo.

Step 1: Login to Azure DevOps portal and click on “Organization settings”

https://dev.azure.com/<Your_Organization_Name>/_settings/organizationOverview

Step 2: Navigate to Pipelines > Agent pools and click “Add pool”.

How to install, configure and add a self-hosted agent in Azure DevOps?

Step 3: From the “Pool type” drop-down select “Self-hosted”, provide a name and description and click “Create”.

How to install, configure and add a self-hosted agent in Azure DevOps?

Step 4: Click on the newly create pool and then click on “New agent”.

How to install, configure and add a self-hosted agent in Azure DevOps?

Step 5: Select the OS and architecture and copy the download link.

How to install, configure and add a self-hosted agent in Azure DevOps?

Note: For this demo I am using an AWS EC2 instance with Amazon Linux 2 OS to host the Azure self-hosted agent.

Step 6: Install self-hosted agent on your system.

Step 7: Configure and add self-hosted agent for Azure DevOps.

How to install, configure and add a self-hosted agent in Azure DevOps?

Now if you refresh the Azure DevOps agent page, this new self-hosted agent will be listed there.

How to install, configure and add a self-hosted agent in Azure DevOps?

Next, we are going to test this newly deployed self-hosted agent by running a Azure Pipeline on it.

Step 8: Create a new Azure repo in any of the project under your Azure DevOps organization and add below file in it.

Observe: We are using our self-hosted agent using “pool: mypool” parameter in the above yaml file.

Step 9: Add a new Azure pipeline inside the project where you have created the new Azure repo in the previous step.

Navigate to “Pipelines” and click “Create Pipeline”.

How to install, configure and add a self-hosted agent in Azure DevOps?

Select “Azure Repos Git”.

How to install, configure and add a self-hosted agent in Azure DevOps?

Select the repository created in step 8.

How to install, configure and add a self-hosted agent in Azure DevOps?

Select “Existing Azure Pipelines YAML file”.

How to install, configure and add a self-hosted agent in Azure DevOps?

From the drop-down select your Azure repo branch and the location of the file azure-pipelines.yml and click “Continue”.

How to install, configure and add a self-hosted agent in Azure DevOps?

Click on “Save” to save the pipeline configuration and then click on “Run” to run the Azure pipeline manually.

How to install, configure and add a self-hosted agent in Azure DevOps?

Our new Azure Pipeline gets executed successfully in our self-hosted runner.

How to install, configure and add a self-hosted agent in Azure DevOps?

You can also view details of the execution by clicking on any stages or jobs.

How to install, configure and add a self-hosted agent in Azure DevOps?

Hope you have enjoyed this article. To know more about Azure DevOps, please refer below official documentation

https://docs.microsoft.com/en-us/azure/devops/?view=azure-devops

Leave a Reply