Build an Azure virtual machine using an Azure RM template

Azure Pipelines | Azure DevOps Server 2019 | TFS 2018 | TFS 2017 | TFS 2015

Note

In Microsoft Team Foundation Server (TFS) 2018 and previous versions, run and release pipelines are called definitions, runs are called builds, service connections are called service endpoints, stages are called environments, and jobs are called phases.

In just a few steps, you can provision Azure virtual machines (VMs) using Resource Manager (RM) templates. Managing the pipelines for virtual machines in this way is considered Infrastructure as code and is a good DevOps practice.

For this example, the template for creating the Azure VMs must be checked into a version control repository along with the rest of the application code, and it must be published as part of the build output.

Create the template

Before you can build the solution, you must create an Azure RM template. Follow these steps to create and check-in a new Resource Manager template.

  1. In Visual Studio, choose File | Add | New project and add a new Azure Resource Group project to your solution.

  2. When prompted for an Azure template, select Windows Virtual Machine.

    The Windows Virtual Machine template is a simple example of provisioning a single virtual machine in Azure. For provisioning other types of resources, you can either edit the WindowsVirtualMachine.json file, select other templates in the project creation wizard, or download one of the many templates available at https://github.com/Azure/azure-quickstart-templates.

  3. Add a project for your app to the solution. This could be a project for an existing app, or a new project created from the Visual Studio File | Add | New project menu.

  4. Save the entire solution (not just the project) and commit the changes into a Team Foundation Server or Azure Repos Git repository.

Create the build pipeline

Carry out the following steps to publish an artifact with the Resource Manager template files.

  1. Create a new build pipeline for the solution you just checked into a TFS or Git repo.

  2. Enable continuous integration (CI). This tells the system to queue a build whenever someone on your team commits or checks in new code.

  3. Publish the artifacts from the build. Make sure that the template files from your ARM template project are included in the artifacts published by your build pipeline.

  4. Save the pipeline and queue a new build. Verify that the artifact contains the Templates folder containing the template files WindowsVirtualMachine.json and WindowsVirtualMachine.parameters.json. This is the template that your release pipeline will consume to provision an Azure virtual machine.

Provision your virtual machine

After you've run the build, you're ready to create a release pipeline to provision your virtual machine:

icon Provision an Azure virtual machine using an Azure RM template

Q & A

I use TFS on-premises and I don't see some of these features. Why not?

Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.

Help and support