Integrate Azure DevTest Labs Environments into your VSTS continuous integration and delivery pipeline


You can use the Azure DevTest Labs Tasks extension that is installed in Visual Studio Team Services (VSTS) to easily integrate your CI/CD build-and-release pipeline with Azure DevTest Labs.  These extensions make it easier to quickly deploy an "environment" for a specific test task and then delete it when the test is finished. This article shows how to create and deploy an environment, then delete the environment, all as one complete pipeline. You would ordinarily perform each of these tasks individually in your own custom build-test-deploy pipeline.  The extensions used in this post are in addition to the create/delete DTL VM tasks:

  • Create an Environment
  • Delete an Environment

 

Before you begin

Before you can integrate your CI/CD pipeline with Azure DevTest Labs, you must install the extension from Visual Studio Marketplace.

  1. Go to Azure DevTest Labs Tasks.
  1. Select Install.
  1. Complete the wizard.

Create and configure the lab for Environments

This section describes how to create and configure a lab where the Azure environment will be deployed to.

  1. A DevTest Lab will need to be created to deploy the environment to.
  1. To configure the lab and create the environment template, complete the procedure in Create multi-VM environments and PaaS resources with Azure Resource Manager templates.
  1. For this example, we’ll use an existing Azure Quickstart Template https://azure.microsoft.com/en-us/resources/templates/201-web-app-redis-cache-sql-database/
  1. Copy the 201-web-app-redis-cache-sql-database folder into the ArmTemplate folder in the repository configured in step 2.

Create a release definition in Release Management

To create the release definition, do the following:

  1. On the Releases tab of the Build & Release hub, select the plus sign (+) button.
  1. In the Create release definition window, select the Empty template, and then select Next.
  1. Select Choose Later, and then select Create to create a new release definition with one default environment and no linked artifacts.
  1. To open the shortcut menu, in the new release definition, select the ellipsis (...) next to the environment name, and then select Configure variables.
  1. In the Configure - environment window, for the variables that you use in the release definition tasks, enter the following values:
  1. For administratorLogin, enter the SQL Administrator login name.
  1. For administratorLoginPassword, enter the password to be used by the SQL Administrator login. Use the "padlock" icon to hide and secure the password.
  1. For databaseName, enter the SQL Database name.
  2. These variable are specific for the example environments, different environments may have different variables.

Create an Environment

The next stage of the deployment is to create the Environment to be used for development or testing purposes.

  1. In the release definition, select Add tasks.
  1. On the Tasks tab, add an Azure DevTest Labs Create Environment task. Configure the task as follows:
    1. For Azure RM Subscription, select a connection in the Available Azure Service Connections list, or create a more restricted permissions connection to your Azure subscription. For more information, see Azure Resource Manager service endpoint.
    2. For Lab Name, select the name of the instance that you created earlier*.
    3. For Repository Name, select the repository where the ARM template (201) has been pushed to*.
    4. For Template Name, select the name of the environment that you saved to your source code repository*.
      1. *The Lab Name, Repository Name, and Template Name are the “friendly” representations of the Azure Resource Ids.  Manually entering the “friendly”       name will cause failures, use the pulldowns to select the information.
    5. For Environment Name, enter a name to uniquely identify the environment instance within the lab.  This must be unique within the lab.
    6. The Parameter File and the Parameters, allow custom parameters to be passed to the environment.  Either or both can be used to set the parameter values, for this example the Parameters section will be used. Use the names of the variables that you defined in the environment, for example:
      1. -administratorLogin “$(administratorLogin)” -administratorLoginPassword “$(administratorLoginPassword)” -databaseName “$(databaseName)” -cacheSKUCapacity 1
    7. Information within the environment template can be passed through in the output section of the template.  Check Create output variables based on the environment template output so other tasks can use the data. $(Reference name.Output Name) is the pattern to follow.  For example, if the Reference Name was DTL and the output name in the template was location the variable would be “$(DTL.location)”.

Delete the Environment

The final stage is to delete the Environment that you deployed in your Azure DevTest Labs instance. You would ordinarily delete the Environment after you execute the dev tasks or run the tests that you need on the deployed resources.

In the release definition, select Add tasks and then, on the Deploy tab, add an Azure DevTest Labs Delete Environment task. Configure it as follows:

  1. To delete the VM, see Azure DevTest Labs Tasks.
    1. For Azure RM Subscription, select a connection in the Available Azure Service Connections list, or create a more restricted permissions connection to your Azure subscription. For more information, see Azure Resource Manager service endpoint.
    2. For Lab Name, select the lab where the environment exists.
    3. For Environment Name, enter the name of the environment to be removed.
  1. Enter a name for the release definition, and then save it.

Next steps

Have a question? Check out the answers or ask a new one at MSDN forum.

Roger Best, Senior Software Engineer

Roger is part of the Visual Studio and .NET engineering team focused on Visual Studio and Azure customers.  He has been at Microsoft for 20 years, focusing on developer technologies for the past decade or so.  In his spare time, he watches too many movies, and tries to survive triathlons


Comments (0)

Skip to main content