{"id":9781,"date":"2015-07-31T04:46:00","date_gmt":"2015-07-31T04:46:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2015\/07\/31\/continuous-deployment-devtest-in-azure-and-deploy-to-production-on-premises\/"},"modified":"2022-08-02T01:00:14","modified_gmt":"2022-08-02T09:00:14","slug":"continuous-deployment-devtest-in-azure-and-deploy-to-production-on-premises","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/continuous-deployment-devtest-in-azure-and-deploy-to-production-on-premises\/","title":{"rendered":"Continuous Deployment: Dev\/Test in Azure and Deploy to Production On-premises"},"content":{"rendered":"<p>Easily provision the required resources in <a href=\"https:\/\/azure.microsoft.com\/en-in\/free\/\" target=\"_blank\" rel=\"noopener\">Microsoft Azure<\/a> using the <a href=\"https:\/\/azure.microsoft.com\/en-in\/documentation\/articles\/resource-group-authoring-templates\/\" target=\"_blank\" rel=\"noopener\">Azure Resource Manager templates<\/a>, and deploy Web applications and SQL Server Databases to the Azure Virtual Machines (VMs), and run tests that are automatically distributed across VMs using the Visual Studio Test Agent. Once the application&#8217;s functionality is verified, deploy the application to on-premises machines using the same IIS\/SQL tasks\u00a0that were used to deploy the app to the Azure VMs. The tasks provide an easy way to override the database connection strings,\u00a0and any of the parameters that are changing\u00a0between development, testing, staging\u00a0and production.<\/p>\n<p>The blog explains how to build the app and deploy it to the Azure VMs using Build and Release Definitions in Visual Studio Team Services (VSTS) and Team Foundation Server (TFS), and then to deploy the app to production on-premises.<\/p>\n<h2>Service Endpoints<\/h2>\n<p>To deploy to Azure, an Azure subscription has to be linked to the VSTS\/TFS account using the Services tab in the Account Administration section.\u00a0The sample app is in the <a href=\"https:\/\/github.com\/fabrikamfiber\/customerservice\" target=\"_blank\" rel=\"noopener\">FabrikamFiber<\/a> GitHub repository. Using the Services tab we will link the GitHub repo to the VSTS\/TFS account.<\/p>\n<h4>Add Azure Resource Manager Subscription<\/h4>\n<p>Add the Azure subscription to use in the Build tasks by opening the <strong>Account Administration<\/strong> screen (gear icon on the top-right of the screen) and then click on the <strong>Services<\/strong> tab. Select** Azure Resource Manager** from the Add <strong>New Service Endpoint<\/strong>\u00a0drop-down. Create a Service Principal as per the steps provided <a href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2015\/10\/04\/automating-azure-resource-group-deployment-using-a-service-principal-in-visual-studio-online-buildrelease-management\/\" target=\"_blank\" rel=\"noopener\">here<\/a>. Also, note the <strong>GitHub<\/strong> in the **New Service Endpoint **drop-down, as this will be used to setup a GitHub repository connection in the section below.<\/p>\n<p><img decoding=\"async\" class=\" size-full wp-image-17935 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/Services.png\" alt=\"Services\" width=\"190\" height=\"38\" \/><\/p>\n<p style=\"text-align: center\">\n  \u00a0Figure: Opening the Account Administration Screen.\n<\/p>\n<p style=\"text-align: center\">\n  <a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/AzureRMEndpoint.png\"><img decoding=\"async\" class=\" size-mediumlarge wp-image-17955 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/AzureRMEndpoint-500x296.png\" alt=\"AzureRMEndpoint\" width=\"500\" height=\"296\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure: Selecting an Azure connection from the Add New Service Connection.\n<\/p>\n<p style=\"text-align: left\">\n  Fill in the required details in the <strong>Add Azure Resource Manager Subscription<\/strong> dialog. Note that the <strong>Create New SPN functionality is coming soon <\/strong>and will ease the process of creating Service Principals.\n<\/p>\n<p style=\"text-align: center\">\n  <a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/AzureRMSPNConnection.png\"><img decoding=\"async\" class=\"size-mediumlarge wp-image-18055 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/AzureRMSPNConnection-424x350.png\" alt=\"AzureRMSPNConnection\" width=\"424\" height=\"350\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure: Adding the details of the\u00a0Service Principal in the\u00a0Add Azure Resource Manager Subscription dialog box.\n<\/p>\n<h4 style=\"text-align: left\">\n  Add New GitHub Service Connection\n<\/h4>\n<p>Select** GitHub<strong>\u00a0from the Add **New Service Endpoint<\/strong>\u00a0drop-down, and fill in the parameters as shown below. Note that the Connection Name can be anything that you like but the token has to be as listed below. After entering the parameters click on OK.<\/p>\n<p><strong>Choose Authorization:<\/strong> Personal access token<\/p>\n<p><strong>Token:<\/strong> 13b56d00b0b78d1c26ab359df7a44014085efa37<\/p>\n<p><strong>Connection Name:<\/strong> FabrikamFiber GitHub<\/p>\n<p style=\"text-align: center\">\n  <a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/GitHubEndpoint.png\"><img decoding=\"async\" class=\" size-mediumlarge wp-image-17975 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/GitHubEndpoint-500x299.png\" alt=\"GitHubEndpoint\" width=\"500\" height=\"299\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure: Adding the\u00a0GitHub repo details in the Add New GitHub Service Connection dialog box.\n<\/p>\n<h2>Automation\u00a0Agent<\/h2>\n<p>An automation\u00a0agent, also called as build agent, has to be deployed on a machine to build the code and to run the tasks. The agent is xcopy deployable, and does not need any installation. The agent can be deployed on machines behind the Firewall and also on Azure VMs. The agent uses the HTTPS protocol to communicate with VSTS\/TFS and can work across proxies and firewalls. VSTS also provides <a href=\"https:\/\/www.visualstudio.com\/docs\/build\/agents\/hosted-pool\" target=\"_blank\" rel=\"noopener\">Hosted automation\u00a0agents<\/a> that can be used to build code and to deploy the application. The Hosted agents are made available on-demand and run on Azure.<\/p>\n<p>Deploy the Windows build agent as per the instructions in the Build <a href=\"https:\/\/msdn.microsoft.com\/Library\/vs\/alm\/Build\/agents\/windows\">docs<\/a>. The following are some of the issues that one should keep in mind while deploying the build agent:<\/p>\n<ol>\n<li>As described in the Build docs, either use the default queue or create a new queue.<\/li>\n<li>Provide the rights to the account, under which the Build agent is running, in the VSTS\u2019s or TFS&#8217;s Control Panel named Agent Pools. This account should be added to the Agent Pool Service Accounts group.<\/li>\n<li>Download and configure the agent by following the instructions.<\/li>\n<li>The tasks described in the blog needs <a href=\"https:\/\/www.visualstudio.com\/en-us\/downloads\/download-visual-studio-vs.aspx\">Visual Studio 2015<\/a>\u00a0and Azure PowerShell to be installed on the build agent.\u00a0Visual Studio 2015 is needed\u00a0for building the code and Azure PowerShell is needed to deploy\u00a0Azure Resource Groups. Azure PowerShell can be installed from <a href=\"https:\/\/github.com\/Azure\/azure-powershell\/releases\/tag\/v1.3.0-March2016\">Azure PowerShell Installer v1.3.0<\/a>.<\/li>\n<\/ol>\n<h2>IIS Web App Deployment \u00a0Using WinRM Extension<\/h2>\n<p>The extension is needed because it has the tasks to deploy IIS Wweb apps and to deploy SQL Server database. Install the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscs-rm.iiswebapp\" target=\"_blank\" rel=\"noopener\">extension<\/a> from the VSTS marketplace. For TFS, download the extension and install it.<\/p>\n<h2>Dev\/Test Applications on Azure<\/h2>\n<p>Follow the directions below to build the app in \u00a0the <strong>Build<\/strong>\u00a0hub and to deploy it to Azure VMs from the <strong>Release<\/strong> hub.<\/p>\n<h4>Create Build Definition &amp; Link the GitHub Repository<\/h4>\n<p>Open the <strong>BUILD<\/strong> hub and choose the <img decoding=\"async\" src=\"\" alt=\"plus\" \/> icon to create a new build definition.<\/p>\n<p style=\"text-align: center\">\n  <a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/CreateBD.png\"><img decoding=\"async\" class=\"size-mediumlarge wp-image-18125 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/CreateBD-500x131.png\" alt=\"CreateBD\" width=\"500\" height=\"131\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure: Creating a new Build Definition.\n<\/p>\n<p style=\"text-align: left\">\n  In the <strong>Build<\/strong>\u00a0tab of the <strong>Create new build definition<\/strong> dialog, select an\u00a0<strong>Empty<\/strong>\u00a0definition and choose <strong>Next<\/strong>.\n<\/p>\n<p style=\"text-align: center\">\n  <a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/NewBD.png\"><img decoding=\"async\" class=\"size-mediumlarge wp-image-18275 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/NewBD-315x350.png\" alt=\"NewBD\" width=\"315\" height=\"350\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure: Selecting the\u00a0Build Definition template.\n<\/p>\n<p style=\"text-align: left\">\n  Select <strong>GitHub<\/strong>\u00a0as the <strong>Repository Source, <\/strong>and then click on the\u00a0<strong>Create<\/strong> button.\n<\/p>\n<p style=\"text-align: center\">\n  <a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/SelectingRepo.png\"><img decoding=\"async\" class=\"size-mediumlarge wp-image-18145 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/SelectingRepo-317x350.png\" alt=\"SelectingRepo\" width=\"317\" height=\"350\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure: Selecting the\u00a0Build Definition template.\n<\/p>\n<p style=\"text-align: left\">\n  In the Build Definition, click on the Repository tab and select the fabrikamfiber\/customerservice <strong>Repository<\/strong>.\n<\/p>\n<p style=\"text-align: center\">\n  <a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/SetRepo.png\"><img decoding=\"async\" class=\"size-mediumlarge wp-image-18185 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/SetRepo-500x231.png\" alt=\"SetRepo\" width=\"500\" height=\"231\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure:\u00a0Setting the repository.\n<\/p>\n<p style=\"text-align: left\">\n  In the Definition, click on the Build tab, and then on \u00a0Add Build Step button\u00a0to add tasks to the Definition.\n<\/p>\n<p style=\"text-align: left\">\n  <img decoding=\"async\" class=\"size-full wp-image-18195 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/AddBuildStep.png\" alt=\"AddBuildStep\" width=\"143\" height=\"26\" \/>\n<\/p>\n<p style=\"text-align: left\">\n  In the <strong>Add Tasks<\/strong> dialog, click on the hyperlink\u00a0<strong>All<\/strong>,<strong>\u00a0<\/strong>and then add the\u00a0tasks &#8211; <strong>NuGet Installer, Visual Studio Build &#038; Copy and Publish Build Artifacts<\/strong>. The tasks are sorted alphabetically, and the <strong>Add<\/strong> button in front of the task, has to be clicked to add the task to the definition.\n<\/p>\n<p style=\"text-align: left\">\n  <a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/AddBuildTasks.png\"><img decoding=\"async\" class=\"size-mediumlarge wp-image-18235 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/AddBuildTasks-342x350.png\" alt=\"AddBuildTasks\" width=\"342\" height=\"350\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure:\u00a0Add\u00a0the tasks to the Build Definition.\n<\/p>\n<p style=\"text-align: left\">\n  Leave the <strong>NuGet Installer task<\/strong> with it&#8217;s default values. Select the <strong>Visual Studio Build task<\/strong> in the Definition, and in the <strong>MSBuild Arguments<\/strong> parameter, enter the value as shown below in a single line. This will build the zip file that can be deployed using Web Deploy later on in a release definition. Leave everything else at their default values:\n<\/p>\n<p style=\"text-align: left\">\n  <strong>\/p:DeployOnBuild=true \/p:WebPublishMethod=Package \/p:PackageAsSingleFile=true \/p:SkipInvalidConfigurations=true \u00a0\/p:PackageLocation=&#8221;$(build.sourcesDirectory)pkg&#8221;<\/strong>\n<\/p>\n<p style=\"text-align: left\">\n  \u00a0<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/VisualStudioBuildTask1.png\"><img decoding=\"async\" class=\"size-mediumlarge wp-image-18285 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/VisualStudioBuildTask1-500x182.png\" alt=\"VisualStudioBuildTask1\" width=\"500\" height=\"182\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure: Defining the parameters for the Visual Studio Build task.\n<\/p>\n<p style=\"text-align: left\">\n  Select the <strong>Copy and Publish Build Artifacts task<\/strong>\u00a0in the Definition and enter or select the following values for the parameters. The built app code has to be published as an artifact to use in the release definitions:\n<\/p>\n<p style=\"text-align: left\">\n  <strong>Copy Root<\/strong>: $(build.sourcesDirectory)\n<\/p>\n<p style=\"text-align: left\">\n  <strong>Contents<\/strong>: Note that these are multi-line values.\n<\/p>\n<p style=\"text-align: left\">\n  **pkg **FabrikamDBbinRelease **FabrikamFiber.Web.TestsbinRelease **DeployTemplate\n<\/p>\n<p style=\"text-align: left\">\n  <strong>Artifact Name<\/strong>:\u00a0FabrikamCustomerService\n<\/p>\n<p style=\"text-align: left\">\n  <strong>Artifact Type<\/strong>: Server\n<\/p>\n<p style=\"text-align: left\">\n  <a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/05\/CopyAndPublishArtifactsTask.png\"><img decoding=\"async\" class=\"size-mediumlarge wp-image-18245 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/CopyAndPublishArtifactsTask-500x105.png\" alt=\"CopyAndPublishArtifactsTask\" width=\"500\" height=\"105\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure: Defining the parameters for the Copy and Publish Build Artifacts task.\n<\/p>\n<p>Click on the <strong>Save button in the Definition<\/strong>, and in the <strong>Save dialog<\/strong>, enter the name of the definition as\u00a0Fabrikam.CustomerService.CI, and then click the <strong>OK<\/strong> button.<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-18255 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/SaveButton.png\" alt=\"SaveButton\" width=\"85\" height=\"36\" \/><\/p>\n<p>After saving the definition, click on the <strong>Queue Build button in the Definition<\/strong>, and then click <strong>OK<\/strong> in the <strong>Queue Build<\/strong> dilaog, to build the app, and to publish the artifacts<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-18265 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/QueueBuild.png\" alt=\"QueueBuild\" width=\"134\" height=\"36\" \/>.<\/p>\n<h4>Create Release\u00a0Definition\u00a0to Deploy and Test the App<\/h4>\n<p>The Azure Resource Group Deployment task is used to deploy Resource Groups in Azure using the <a href=\"https:\/\/azure.microsoft.com\/en-in\/documentation\/articles\/resource-group-template-deploy\/\">Azure Resource Manager templates<\/a>.<\/p>\n<p style=\"text-align: center\">\n  <a href=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/4010.Im5_.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/4010.Im5_.png\" alt=\"\" border=\"0\" \/><\/a>\n<\/p>\n<p style=\"text-align: center\">\n  Figure: Azure Resource Group Deployment task in the Build Definition to deploy a Resource Group on Azure.\n<\/p>\n<p>The different parameters of the task are as described below:<\/p>\n<p><strong>Azure Subscription<\/strong>: Select the Azure Subscription where the Resource Group will be deployed. This is a dropdown of the subscriptions that have been added in the Services tab.<\/p>\n<p><strong>Resource Group, Location<\/strong>: The name of the Resource Group and its location. If this is an existing Resource Group then the task will update the Resource Group with the Resources specified in the Azure template. If no Resource Group with the name exists in the Subscription then a new one will be created.<\/p>\n<p><strong>Template and its Parameters<\/strong>: The templates and the templates parameters file are the Azure templates available at <a href=\"https:\/\/github.com\/Azure\/azure-quickstart-templates\">GitHub<\/a>\u00a0and in the <a href=\"https:\/\/azure.microsoft.com\/en-in\/documentation\/articles\/powershell-azure-resource-manager\/\">Azure gallery<\/a>. To get started immediately, use <a href=\"https:\/\/aka.ms\/sampletemplate\">this<\/a> template that is available on GitHub. These files can be either checked in the Version Control of they can be part of the build itself. If the files are part of the Build, use the pre-defined <a href=\"https:\/\/msdn.microsoft.com\/Library\/vs\/alm\/Build\/scripts\/variables\">system variables<\/a> provided by the Build to specify their location. The variables to use are $(Build.Repository.LocalPath), if the templates are checked-in but are not built, or $(Agent.BuildDirectory), if the templates are built as part of the solution. Be sure to specify the full path like $(Build.Repository.LocalPath)Azure TemplatesAzureRGDeploy.json. Wildcards like ***.json or ***.param.json are also supported and there needs to be only file that matches the search pattern at the location. If more than one file matches the search pattern then the task will error out.<\/p>\n<p><strong>Override Template Parameters<\/strong>: The Override template parameters is used to override the parameters, like \u2013storageAccountName azurerg \u2013adminUsername $(vmusername) \u2013azureKeyVaultName $(fabrikamFibre).<\/p>\n<p><strong>Advanced Deployment Options<\/strong>: This section can be confusing if one does not understand the rationale behind the options. The following information will help in understanding the parameters and the proper use of them:<\/p>\n<ul>\n<li><strong>Refresh SAS Token<\/strong>: Azure provides in-built ability to deploy applications using Resource Extensions (RE) for PowerShell-DSC or Custom Script Extension for any of the scripting languages for Linux (Python, Shell scripts). The scripts and application files need to be available on an Azure storage account because the RE downloads them to the VMs and then runs them. The storage accounts are normally secured, and a Shared Access Signature (SAS) token is needed to access them. More information about the Azure SAS token is <a href=\"https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/storage-dotnet-shared-access-signature-part-1\/\">here<\/a>. This SAS token has an expiration date and the storage account cannot be accessed after the SAS token expires. This will break the Continuous Integration (Build) pipeline because the task will fail as it cannot access the storage account. The Refresh SAS token parameter refreshes the SAS token in the Azure template prior to sending it to Azure each time the Build is run. To do that it needs the name of the parameters for Azure Blob and SAS token as they have been specified in the Azure template parameters file. Multiple of these can be provided in Azure Blob Parameter and SAS Token Parameter by using the semi-colon delimiter like azurestore1; azurestore2; azurestore3. For example, the template parameters file has the following key-value pairs for Azure Storage account and SAS token. Then fill in azureStorage in the Azure Blob Parameter in the Azure Resource Deployment task and sasToken in the SAS Token Parameter.Note that Refresh SAS token is optional and only needed if deployment is being done to the Azure VMs using the Azure Resource Extension. As demonstrated in this blog, if the PowerShell on Target Machines task is being used to deploy the app then this Refresh SAS token is not needed.<\/li>\n<\/ul>\n<p style=\"text-align: left;padding-left: 60px\">\n  <code class=\"js\">\"azureStorage\": {\n\"value\": \"fabrikamfibre\"\n},\n\"sasToken\": {\n\"value\": \" ?sv=2014-02-14&sr=c&sig=Dj1QOJups1%2Bf%2Beq989j%2FomowbmNS8Q2Qmf5eJEU9FGg%3D&st=2015-03-26T18%3A30%3A00Z&se=2015-04-03T18%3A30%3A00Z&sp=r\"\n}<\/code>\n<\/p>\n<ul>\n<li><strong>Virtual Machine Credentials<\/strong>: These are the Admin credentials for the Azure VMs that have been specified in the Azure template. The VM credentials are stored securely in the Deployment service, so that any subsequent tasks that need to access the VMs will not have to take this as an input. In this walkthrough, the tasks that need the credentials are Azure File Copy, PowerShell on Remote Machines, and Visual Studio Test Agent Deployment.<\/li>\n<li><strong>Test Certificate<\/strong>: The test certificate parameter requires background knowledge that is explained below. This parameter will be explained post the sections below.<\/li>\n<\/ul>\n<p style=\"text-align: left\">\n  <strong>Setting-up WinRM HTTPS on Azure VMs: <\/strong>Tasks like Azure File Copy, PowerShell on Target Machines, Visual Studio Test Agent Deployment run on the Build Agent machine and copy files or deploy apps to Azure VMs using the WinRM HTTPS protocol. For these tasks to work properly the WinRM HTTPS port (default port is 5986) needs to be opened and configured properly on the VMs. Opening the ports and configuring them with the certificates is done using the Azure templates. The <a href=\"https:\/\/aka.ms\/sampletemplate\">sample template<\/a> uploaded on GitHub shows how to enable the WinRM HTTPS port on Azure VMs and map them to a Public IP using the Azure resource provider\u2019s wiz. Network Interfaces, Load Balancers and Virtual Machines. In addition, it also shows how to specify the Azure Key Vault and its secret, to download and install the certificate on the VM.\n<\/p>\n<p><strong>Azure Key Vault and Test Certificates<\/strong>: Azure Key Vault provides a secure way of storing certificates in Azure that can be easily downloaded and installed on the Azure VMs to enable WinRM HTTPS communication protocol. To create test certificates and to upload the certificates to Azure Key Vault follow the steps given below. Note that the Azure Key Vault can be in its own resource group and does not need to be in the resource group that is being dynamically created using the Azure Resource Group Deployment task. This way, once a certificate has been uploaded to the Azure Key Vault it can be reused across different Azure resource group deployments.<\/p>\n<ul>\n<li>Run the following commands from the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ms229859(v=vs.110).aspx\">developer command prompt<\/a> to create the test certificate. Replace the Common Name (CN) with the Resource Group name and the password with the real password.<\/li>\n<\/ul>\n<pre class=\"scroll\" style=\"padding-left: 60px\"><code class=\"csharp\">makecert -sv armtest.pvk -n \"cn=*.westus.cloudapp.azure.com\" armtest.cer -b 06\/06\/2015 -e 06\/06\/2016 -r\npvk2pfx -pvk armtest.pvk -spc armtest.cer -pfx armtest.pfx -po password<\/code><\/pre>\n<ul>\n<li>For uploading the certificate to the Azure Key Vault follow the steps given below: \n<ul>\n<li>Download the KeyVaultUrl.ps1 available with this blog to the local disk. Remember to unblock the zip file after downloading it, else the KeyVaultUrl.ps1 will not run.<\/li>\n<li>Open Windows Azure PowerShell<\/li>\n<li>Change directory to where the KeyVaultUrl.ps1 file was copied to.<\/li>\n<li>Run the following commands:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre class=\"scroll\" style=\"padding-left: 60px\"><code class=\"csharp\"> Add-AzureAccount \n Select-AzureSubscription -SubscriptionName &lt;name&gt; \n Switch-AzureMode AzureResourceManager \n Import-Module .KeyVaultUrl.ps1 \u2013Force<\/code><code class=\"csharp\">\n<\/code><\/pre>\n<ul>\n<li>To generate the secret Id run the command given below:<\/li>\n<\/ul>\n<pre class=\"scroll\" style=\"padding-left: 60px\"><code class=\"csharp\">$a = Generate-KeyVaultUrl -resourceGroupName &lt;resourceGroupName&gt; -keyVaultName &lt;KeyVaultName&gt; -secretName &lt;secretName&gt; -location &lt;location&gt; -certificatePath &lt;certPath&gt; -password &lt;password&gt;<\/code><\/pre>\n<ul>\n<li>Example:<\/li>\n<\/ul>\n<pre class=\"scroll\" style=\"padding-left: 60px\"><code class=\"csharp\">$a = Generate-KeyVaultUrl -resourceGroupName nikhilnew13 -keyVaultName nikhilkeyvalut13 -secretName test -location \"West US\" -certificatePath \"D:certArmTest.pfx\" -password password<\/code><\/pre>\n<ul>\n<li>Secret Id will get printed as well as get stored in $a variable and it will be similar to \u2013 <a href=\"https:\/\/fabrikamvalut.vault.azure.net:443\/secrets\/fabrikam\/256892c857714ec0bd76529147cf6b11\">https:\/\/fabrikamvalut.vault.azure.net:443\/secrets\/fabrikam\/256892c857714ec0bd76529147cf6b11<\/a><\/li>\n<\/ul>\n<p><strong>Test Certificate<\/strong>: The Build Agent uses the <a href=\"https:\/\/support.microsoft.com\/en-us\/kb\/2019527\">WinRM_HTTPS<\/a>\u00a0communication protocol to deploy apps to the Azure VMs. For secure communication, certificates are used and they need to be installed on the VMs. For developing and testing apps, usually test certificates are used, and by checking-off the Test Certificate parameter, the trusted certificate authority (CA) validation is skipped. Note that the Common Name (CN) of the certificate has to be same as that of the Fully Qualified Domain Name (FQDN) of the VM. If the CN and FQDN different then the task will error out.<\/p>\n<h3>Azure File Copy<\/h3>\n<p>The task is used to copy application files and other artifacts that are required to install the application on Azure VMs like PowerShell scripts, PowerShell-DSC modules etc.<\/p>\n<p><img decoding=\"async\" style=\"margin-right: auto;margin-left: auto\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/8030.lm6_.png\" alt=\"\" border=\"0\" \/><\/p>\n<p style=\"text-align: center\">\n  Figure: Azure File Copy for copying files to Azure blobs or Azure VMs.\n<\/p>\n<p>The task provides the ability to copy files to an Azure blob or directly to Azure VMs. Even when the target is Azure VMs, Azure blobs are used as an intermediary and the files are copied to it first and then downloaded to the VMs. The tasks uses <a href=\"https:\/\/azure.microsoft.com\/en-in\/documentation\/articles\/storage-use-azcopy\/\">AzCopy<\/a>, the command-line utility built for fast copying of data from and into Azure storage accounts. The different parameters for copying files to Azure VMs are as described below:<\/p>\n<p><strong>Azure Subscription:<\/strong> The name of Azure subscription, where the Azure storage account is located. The storage account is accessed using the stored credentials of the Azure account in the Services tab.<\/p>\n<p>**Source: **The source of the files. As described above using pre-defined system variables like $(Build.Repository.LocalPath) make it easy to specify the location of the build on the Build Automation Agent machine. The variables resolve to the working folder on the agent machine, when the task is run on it. Wild cards like ***.zip are supported and should resolve to a single file or a folder.<\/p>\n<p><strong>Storage Account:<\/strong> The name of an existing storage account in the Azure Subscription specified earlier.<\/p>\n<p>**Destination: **The target for copying the files and is either an Azure blob or VMs. The section below details the parameters that need to be filled-out if the target is Azure VMs. Note that for copying the files to VMs, they are first copied to an automatically generated container in the Azure storage account, and then from there to the VMs. The container is deleted after the files are copied successfully to the VMs.<\/p>\n<ul>\n<li><strong>Resource Group:<\/strong> Name of the resource group that contains the Azure VMs.<\/li>\n<li><strong>Select Machines By: **The parameter is used to copy the files to a subset of VMs and the subset can be specified by the names of the machines or the tags on them. **\u00a0<\/strong><\/li>\n<li><strong>Copy to Machines:<\/strong> If copying to a subset of machines provide a comma separated list of the VMs here, else if using tags then provide the tags in the format Role:Web; OS:win7. The default is to copy to all the VMs in the Resource Group.<\/li>\n<li><strong>Destination Folder<\/strong>: The folder in the Azure VMs where the files will be copied to. Environment variables are also supported like $env:windir, $env:systemroot etc. An example of the destination folder is $env:windirFabrikamFibreWeb.<\/li>\n<li><strong>Clean Target<\/strong>: Checking this option will clean the destination folder prior to copying the files to it.<\/li>\n<li><strong>Copy Files in Parallel:<\/strong> Checking this option will copy files to all the VMs in the Resource Group in-parallel, hence speeding up the process of copying.<\/li>\n<\/ul>\n<p>**Destination: **If the target is Azure blob then the following parameters need to be filled out.<\/p>\n<ul>\n<li><strong>Container Name:<\/strong> The name of the container where the files will be copied to. If the container does not exist then a new one will be created with the name provided in this parameter.<\/li>\n<li><strong>Blob Prefix:<\/strong> A prefix for the Blobs that can be used to filter the blobs like appending the Build number to the blobs, so that all the blobs with the same build number can be downloaded from the Container.<\/li>\n<\/ul>\n<h3>PowerShell on Target Machines<\/h3>\n<p>The task is used run PowerShell on the target machines. The task can run both PowerShell scripts and PowerShell-DSC scripts. For PowerShell scripts, PowerShell 2.0 is needed on the machines and for PowerShell-DSC scripts <a href=\"https:\/\/www.microsoft.com\/en-in\/download\/details.aspx?id=40855&amp;40ddd5bd-f9e7-49a6-3526-f86656931a02=True\">Windows Management Framework 4.0<\/a> needs to be installed on the machines. WMF 4.0 ships in-the-box in Windows 8.1 and Windows Server 20012 R2.<\/p>\n<p><img decoding=\"async\" style=\"margin-right: auto;margin-left: auto\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/6153.lm7_.png\" alt=\"\" border=\"0\" \/><\/p>\n<p style=\"text-align: center\">\n  Figure: PowerShell on Target Machines task runs on the machines to install applications\n<\/p>\n<p>The different parameters of the task are explained below:<\/p>\n<ul>\n<li><strong>Machine Group:<\/strong> The name of the Azure Resource Group.<\/li>\n<li><strong>Select Machines By: **The parameter is used to specify the subset of VMs, where the PowerShell will be run and the subset can be specified by the names of the machines or the tags on them. **\u00a0<\/strong><\/li>\n<li><strong>Deploy to Machines:<\/strong> If deploying to a subset of machines provide a comma separated list of the VMs here, else if using tags then provide the tags in the format Role:Web; OS:win7. The default is to deploy to all the VMs in the Resource Group.<\/li>\n<li>**PowerShell Script: **The location of the PowerShell script on the target machine like c:FabrikamFibreWeb. Environment variables can be also used like %systemdrive%Web or %temp% FabrikamFibreWeb etc.<\/li>\n<li>**Script Arguments: **The arguments needed by the script, if any provided in the following format -applicationPath $(applicationPath) -username $(vmusername) -password $(vmpassword).<\/li>\n<li><strong>Initialization Script:<\/strong> The location of the data script that is used by PowerShell-DSC and the location has to be on the target machine. It is advisable to sue arguments in place of the initialization script.<\/li>\n<li><strong>Advanced Options:<\/strong> The advanced options provide more fine-grained control on the deployment.<\/li>\n<li><strong>Run PowerShell in Parallel:<\/strong> Checking this option will execute the PowerShell in-parallel on all VMs in the Resource Group.<\/li>\n<li><strong>Session Variables<\/strong>: Used for setting-up the session variables for the PowerShell scripts and the input is a comma separated list like $varx=valuex, $vary=valuey. This is mostly used for backward compatibility with the earlier versions of Release Management product and it is advisable to use arguments in place of the session variables.<\/li>\n<\/ul>\n<h3>Visual Studio Test Agent Deployment<\/h3>\n<p>The task is used to deploy the Visual Studio Test Agent on the machines. The task runs on the Build Agent machine and uses PowerShell to deploy the Test Agent to the machines.<\/p>\n<p><img decoding=\"async\" style=\"margin-right: auto;margin-left: auto\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/2260.Im8_.png\" alt=\"\" border=\"0\" \/><\/p>\n<p style=\"text-align: center\">\n  Figure: Visual Studio Test Agent Deployment task runs on the machines to install and configure the test agent.\n<\/p>\n<p>The different parameters of the task are explained below:<\/p>\n<ul>\n<li><strong>Machine Group:<\/strong> The name of the Azure Resource Group.<\/li>\n<li><strong>Select Machines By: **The parameter is used to specify the subset of VMs, where the test agent will be installed, and the subset can be specified by the names of the machines or the tags on them. **\u00a0<\/strong><\/li>\n<li><strong>Deploy to Machines:<\/strong> If deploying to a subset of machines provide a comma separated list of the VMs here, else if using tags then provide the tags in the format Role:Web; OS:win7. The default is to deploy to all the VMs in the Resource Group.<\/li>\n<li>**Username: **The credentials that the test agent will use to run on the machine.<\/li>\n<li>**Password: **The password of the user.<\/li>\n<li>**Interactive Process: **Checking this option will configure the test agent to run as an interactive process and this is needed for running the Coded UI tests.<\/li>\n<li>**Test Agent Location: **The test agent is downloaded and installed on the machines from <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=536423\">http:\/\/go.microsoft.com\/fwlink\/?LinkId=536423<\/a>. The default behavior can be overridden by manually downloading the test agent and then providing the test agent\u2019s location as a UNC or local path.<\/li>\n<li>**Update Test Agent: **Checking this option will update the test agent and its configuration.<\/li>\n<li><strong>Enable Data Collection Only:<\/strong> Checking this option will configure the test agent to only collect data, and no tests can be run using the test agent. Useful when data needs to be collected from the application-under-test.<\/li>\n<\/ul>\n<h3>Visual Studio Test using Test Agent<\/h3>\n<p>The task is used to run tests on the machines where the test agent has been deployed.<\/p>\n<p><img decoding=\"async\" style=\"margin-right: auto;margin-left: auto\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/1321.Im10.png\" alt=\"\" border=\"0\" \/><\/p>\n<p style=\"text-align: center\">\n  Figure: Visual Studio Test using Test task runs tests on the machines where the test agent has been deployed.\n<\/p>\n<p>The different parameters of the task are explained below:<\/p>\n<ul>\n<li><strong>Test Machine Group:<\/strong> The name of the Azure Resource Group where the tests will be run. The test agent should have been already deployed and configured on the VMs using the Visual Studio Test Agent Deployment task.<\/li>\n<li>**Test Drop Location: **The folder on the VMs where the test binaries are located. Environment variables can be also used like %systemdrive%Tests or %temp%Tests etc.<\/li>\n<li>**Test Assembly: **The test binaries for running the tests. Wild cards can be used like **&#42;FabrikamTests&#42;.dll that will use all test assemblies with FabrikamTests in their name.<\/li>\n<li>**Test Filter Criteria: **Used to specify the test filter criteria like \u2018Owner=Tom&amp;Priority=0\u2019.<\/li>\n<li>**Platform: **The platform against which the tests will be reported like any cpu or x86 or x64.<\/li>\n<li>**Configuration: **The configuration against which the tests will be reported like any debug or release.<\/li>\n<li><strong>Run Settings File:<\/strong> The location of the run setting file on the Build Automation Agent machine. Predefined variables like $(Build.Repository.LocalPath) can be also used.<\/li>\n<li><strong>Override Test Run Parameters:<\/strong> Used to override parameters in the TestRunParameters section of the run setting file like WebAppURL=$(appURL);Port=8080. Here the $(appURL) is a variable that has been defined in the Variables tab of the Definition.<\/li>\n<li>**Test Configurations: **Used to associate a test case filter against a test configuration ID. The syantax is <Filter1>:<ID1>; DefaultTestConfiguration:<ID3>, like FullyQualifiedName~Chrome:12.<\/li>\n<li>**Code Coverage Enabled: **Checking this option will enable code coverage during the testing.<\/li>\n<li>**Application Under Test Machine Group: **The name of resource group where the Application under Test is running. If the same resource group is being used for deploying applications and running tests then the name of Test Machine Group and Application Under Test Machine Group will be same.<\/li>\n<\/ul>\n<h3>Machine Group Actions<\/h3>\n<p>The task is used to start\/stop\/restart\/delete Azure Resource Groups.<\/p>\n<p><img decoding=\"async\" style=\"margin-right: auto;margin-left: auto\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2015\/07\/8424.Im11.png\" alt=\"\" border=\"0\" \/><\/p>\n<p style=\"text-align: center\">\n  Figure: Machine Group Actions task to start\/stop\/restart\/delete Azure Resource Groups.\n<\/p>\n<p>The different parameters of the task are explained below:<\/p>\n<ul>\n<li><strong>Azure Subscription:<\/strong> The Azure Subscription, where the resource group is located.<\/li>\n<li>**Machine Group: **The name of the Azure resource group.<\/li>\n<li>**Action: **The action to be performed on the resource group wiz. start, stop, restart, or delete. The block and unblock actions currently do not work with Azure resource groups and once that has been fixed, the updates will be posted to the blog.<\/li>\n<li><strong>Select Machines By: **The parameter is used to specify the subset of VMs on which the action will be performed, and the subset can be specified by the names of the machines or the tags on them. **\u00a0<\/strong><\/li>\n<li><strong>Apply to Machines:<\/strong> If deploying to a subset of machines provide a comma separated list of the VMs here, else if using tags then provide the tags in the format Role:Web; OS:win7. The default is to deploy to all the VMs in the Resource Group.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/6\/2019\/02\/KeyVaultUrlScript.zip\">KeyVaultUrlScript.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Easily provision the required resources in Microsoft Azure using the Azure Resource Manager templates, and deploy Web applications and SQL Server Databases to the Azure Virtual Machines (VMs), and run tests that are automatically distributed across VMs using the Visual Studio Test Agent. Once the application&#8217;s functionality is verified, deploy the application to on-premises machines [&hellip;]<\/p>\n","protected":false},"author":177,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[227,224,226,1],"tags":[],"class_list":["post-9781","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-agile","category-azure","category-ci","category-devops"],"acf":[],"blog_post_summary":"<p>Easily provision the required resources in Microsoft Azure using the Azure Resource Manager templates, and deploy Web applications and SQL Server Databases to the Azure Virtual Machines (VMs), and run tests that are automatically distributed across VMs using the Visual Studio Test Agent. Once the application&#8217;s functionality is verified, deploy the application to on-premises machines [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/9781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/177"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=9781"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/9781\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=9781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=9781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=9781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}