Member-only story

How to Capture the VM ID as a Pipeline Variable in Azure DevOps

Luca Berton
6 min readOct 6, 2024

In many Azure DevOps CI/CD pipelines, deploying infrastructure using Azure Resource Manager (ARM) templates is a common task. Once the infrastructure is deployed (such as a virtual machine in Azure DevTest Labs), you might want to capture certain output values — like the virtual machine ID (VM ID) — for use in subsequent tasks.

In this article, we’ll walk through how to modify your Azure DevOps YAML pipeline to capture the VM ID (labVmId) created by the AzureResourceManagerTemplateDeployment task, and store it as a pipeline variable that can be used later in the pipeline.

Objective

We will modify the pipeline to:

  1. Deploy a virtual machine using an ARM template.
  2. Capture the VM ID (returned from the deployment) as a variable.
  3. Use this captured labVmId in later steps of the pipeline.

Step-by-Step Guide

Step 1: Ensure ARM Template Outputs the VM ID

First, ensure that the ARM template you are using to deploy the virtual machine is configured to output the vmId (or resource ID) of the virtual machine. The outputs section of your ARM template should look like this:

--

--

Luca Berton
Luca Berton

Written by Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday

No responses yet