The ability to treat infrastructure (machines, networks, configuration) in the same way as code brings many benefits, but in particular allows you to create infrastructure on demand and include that in your DevOps pipeline.
Azure Resource Manager (ARM) templates are the native approach and this lab adds using ARM into the flow. The example here will allow you to create an environment in Azure on demand as part of the flow.
This lab will create a new test environment in Azure without needing to manually create it (via the Portal or the Command line etc.).
- In Visual Studio, with the Web App solution open in Solution Explorer, right click the solution and select Add | New Project.
- Select Cloud | Azure Resource Group and name the project e.g. WebApp.ARM.
- There are a range of ARM templates to create a wide variety or resources in Azure. In this case from the Visual Studio Templates select Blank Template and click OK.
- You now have a project in your solution containing a blank ARM template (azuredeploy.json) and a blank parameters file (azuredeploy.parameters.json).
- Now replace the content of the files created in the previous step with pre-prepared content:
- View (or download) this azuredeploy.json file, select all the contents of the file, and then copy and paste over the content of the azuredeploy.json file in Visual Studio.
- Do the same with this azuredeploy.parameters.json file.
- Save the files in Visual Studio.
- In Visual Studio, select the Team Explorer | Changes. Add a commit comment and select Commit All and Push. Save if prompted.
The ARM template is now added to source control, although there is no need for it to be in the same repository as the code, this is just for convenience in this lab. Note that adding the new files to source control will trigger a build and release in the background. You could temporarily turn off the CI trigger but just let it run in the background while completing the next task.
- In Azure DevOps select Pipelines | Releases | select your release definition and Edit pipeline.
- Add a new artifact to the release pipeline. This means the release will get the application from the build (as a zip file) and the ARM templates directly from source control (as they don't need to be compiled or packaged). Set the Source type to Azure Repo, the Project and Source (repository) to the Web App project, the Default branch to master and the default version to Latest from default branch. Then click Add (you may need to scroll down).
- In the Pipeline view hover over the Dev stage and select Clone.
-
Select the cloned stage Copy of Dev and change the name to QA and close the Stage window.
. -
Select the QA stage (by clicking on the "1 job, 1 task" link inside the QA environment) and in Tasks click the plus sign by Run on Agent and then search for the Azure Resource Group Deployment task. Select Add.
- Set the Azure Details. Select the Azure subscription set up previously, Ensure that the Action is Create or update resource group, enter a new resource group name for the QA environment e.g. WebAppQA-RG and set the location.
- In the Template section set the Template (using the ... button) to Web App (Azure Repos Git) WebApp/WebApp.ARM/azuredeploy.json and click OK.
- Set the Template parameters field (using the ... button) to WebApp (Git) WebApp.ARM/azuredeploy.parameters.json and click OK.
- Set the Override Template parameters field (using the ... button) to WebAppQAPlan, the webSiteName to the same as the Dev website but with QA appended (e.g. WebApp-GJAD-QA)and click OK.
-
Move the Azure Deployment: Create or Update Resource Group task to be before the Deploy Azure App Service task by dragging and dropping the task.
-
In the QA deployment process settings set the App service name to the name you used in step 9 above. Save your changes.
- Test the changes by making another code change in Visual Studio(e.g. changing the heading again), committing and pushing, and observe the build and release. After a few minutes you should see that both the Dev and QA stages have been successfully deployed to.
- Explore the Azure portal to find the resource group WebApp-QA-RG and the web app provisioned using ARM in the QA environment. Confirm that the web application has been deployed and open it using the URL in the App service overview.
You have now created a DevOps pipeline that deploys to multiple stages, and provisions the QA stage on demand without a manual process. You could now delete the QA web app in the Azure portal and run the release pipeline again and it will recreate the QA web app.
<- Lab 4: Continuous Deployment | Home | Lab 6: Automated Testing with Selenium ->














