Use an Azure Virtual Machine Scale set as Azure DevOps agents

Author: Akhil M Anil || DevOps Engineer

An agent in  Azure DevOps is a computing infrastructure with installed agent software that runs a job to perform a task/ a set of tasks.

There are different types of agents available for the users such as:

  • Microsoft Hosted Agents
  • Self-hosted Agents
  • Scale Set Agents
Azure Virtual Machine Scale Set Agents

Azure Virtual Machine Scale Set agents is a feature within Azure DevOps. It allows you to use an existing Virtual Machine Scale Set to host your Azure DevOps agents and allows Azure DevOps to manage the scaling out and in of those agents. Therefore, you get the ability to deploy your agents in a private network and control the dependencies that are installed on the agents.

Note:
  • You cannot run Mac agents using scale sets. You can only run Windows or Linux agents this way.
  • Scale set agents currently supports Ubuntu Linux, Windows Server/DataCenter 2016/2019, and Windows 10 client.
In this article, we will configure the Linux Scale Set agent, install some software and run a sample ADO pipeline.

Steps:

  • Provisioning a Linux VM in Azure
    • Open portal.azure.com and click on resources. Select Virtual Machines. Here for this tutorial, I have used Linux 20.04LTS V2.

  • Install the software in VM.
    • To install software in a Linux VM, we need to connect to the VM using SSH. Here I'm using Putty to connect to VM using SSH. Initially copy the public IP of the VM, open Putty and enter the public IP and click open.
    • Connect to VM using username and password which gave at the time of VM creation.
    • Now we install software to VM. For testing purposes, we will install python3 and nodejs. 
  • Generalize the VM, Create a VM image definition
    • Open the Azure portal and open the VM which we created. As a first step stop the VM.
    • After the VM is stopped, click on capture to create an image of the VM.

    • For the target compute gallery, either you can use an existing azure compute gallery or create a new one.
    • Select the operating system state as Generalized.
    • Then create a new image definition.
    • Enter version no. as 0.0.1, the rest all keep as default values.
    • Now click Review and create.
  • Create a VMSS using the VM image definition
    • Open the VM Image definition which we created and click on create VMSS.

    • Make sure you select the scaling policy as manual and uncheck the use load balance checkbox if it is already checked.
    • Rest all keep the default values.
    • click on Review + Create and create VMSS.

  • Add VMSS agent pool in Azure DevOps
    • Open Azure DevOps, click on project settings, and click on Agent pools.
    • Click on Add pool.
    • Select pool type as Azure virtual machine scale set.
    • For Azure Subscriptions, either uses the subscription name and click authorize or create a service connection and use the service connection.
    • Select the VMSS that we created in the previous step.
    • Give a name to the agent pool.
    • For the Maximum number of virtual machines in the scale set, give any number, here I will give 5.
    • For the Number of agents to keep on standby, keep it as 1 or 2
    • Make sure to check the Grant access permission to all pipelines checkbox.

    • Now create the agent pool
    • In order to add the agents to the agent pool. Navigate back to the portal and open the VMSS that we created.
    • Click on Instances, select all the instances and click upgrade.

    • Click on Extensions + applications and we can see  Microsoft.Azure.DevOps.Pipelines.Agent extension gets created automatically.

  • Run the Pipeline 
    • Download the validation.yml from here: Azure-DevOps/VMSS-yml
    • For creating a pipeline, click on pipelines, and click on the new pipeline. select Azure repos git, select the repository, click on existing azure pipelines YAML file and select the validation.yml file
    • Click on Save and Run and Run the pipeline.

The pipeline is successful, and we can see the software are also detected!

Connect me via:

LinkedIn: Akhil M Anil | LinkedIn

References: 

Comments

Popular posts from this blog

Install Java silently using powershell in Azure Windows VM

Configure an Azure DevOps self-hosted Windows agent in Docker

List of Repositories - Authorize Rest API calls using Job Access Token