Member-only story
How to Capture the VM ID as a Pipeline Variable in Azure DevOps
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:
- Deploy a virtual machine using an ARM template.
- Capture the VM ID (returned from the deployment) as a variable.
- 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: