How to Automatically Delete a DevTest Labs VM Using an Azure DevOps Pipeline

Luca Berton
7 min readOct 6, 2024

In Azure DevOps, automating the lifecycle of virtual machines (VMs) deployed in Azure DevTest Labs can be extremely helpful for reducing costs and managing resources efficiently. After performing development tasks or running tests on a deployed VM, it’s best practice to delete the VM when it’s no longer needed.

In this article, we’ll walk through how to automate the deletion of a VM from Azure DevTest Labs by adding a task to your Azure DevOps YAML pipeline. This will ensure that your DevTest Lab environment remains clean and that resources aren’t unnecessarily consumed.

Why Automate VM Deletion?

  1. Cost Management: Running VMs can accumulate costs, especially if left idle. Automatically deleting unused VMs ensures you’re not billed for resources you no longer need.
  2. Resource Management: Azure DevTest Labs encourages efficient resource management. Automatically deleting VMs after use prevents resource congestion and keeps your environment tidy.
  3. Automation: Including a VM deletion step in your CI/CD pipeline simplifies the entire process by ensuring everything, from VM creation to deletion, is handled seamlessly within the same pipeline.

Step-by-Step Guide to Deleting…

--

--

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