Azure Devops & VMSS - part2

Mar. 11, 2021

Azure DevOps & VMSS agents

Good news everyone! Azure DevOps now supports VMSS as agent.

In this series of posts, we’ll cover:

Azure CLI

First, let’s install Azure CLI.

Create the VMSS

We can now create the VMSS. This is super simple!

For a VMSS, you’ll need :

Get your subnet ID by adding /subnets/nameofyoursubnet after the ID of the VNet or by using Azure CLI:

vnetRgName=NAME_OF_THE_RG_VNET
vnetName=NAME_OF_THE_VNET
subnetName=NAME_OF_THE_SUBNET
location=westeurope
az group create --name $vnetRgName --location $location
subnetId=$(az network vnet subnet list -g $vnetRgName --vnet-name $vnetName --query "[?contains(name, '$subnetName')].id" -o tsv)

Now, set a default username, a name for your VMSS, a resource group (it needs to exist before this command) and the subnet ID you got just before.

user=YOUR_USERNAME
vmssName=A_NAME_FOR_VMSS
rgName=NAME_OF_THE_RG
subnetId=ID_OF_YOUR_SUBNET
az group create --name $rgName --location $location
az vmss create \
    --admin-username $user \
    --authentication-type SSH \
    --disable-overprovision \
    --image UbuntuLTS \
    --instance-count 2 \
    --load-balancer "" \
    --name $vmssName \
    --nsg "" \
    --platform-fault-domain-count 1 \
    --public-ip-address "" \
    --resource-group $rgName \
    --single-placement-group false \
    --storage-sku Standard_LRS \
    --subnet $subnetId \
    --upgrade-policy-mode manual \
    --vm-sku "Standard_D2_v3"

And voilà, you have your VMSS. You need to make sure this VMSS can access internet on 80/443 TCP and you’re good to go. We’ll talk security later.

Go to you Azure DevOps portal, at the root (not in a project) and go to the organization settings.

Now, in the left menu, select Agent pools under Pipelines and click on Add pool.

Select Azure virtual machine scale set as type, select a projet (this is needed to store the SPN, see this projet like to mother projet of the scale set. You can the project were you’re gonna store the code of this lab), the Azure subscription where the scale set has been created and finally, the scale set.

Now, you can give it a name, put the min/max number of instances and the idle time. The 3 values can be changed later on.

All done

Azure DevOps is now the owner of the scale set. An extension will be added to install and configure the agent every time an instance is fired up. If you go on your VMSS, you’ll the first 2 instances getting deleted and 3 new ones being provisioned. They’ll be killed after the idle time so, do not worry too much about the cost here.

Resources