Well that doesn’t work, the parameter values are not picked up by the FileTransform Task and so no substitution happens. So, what if we define the variables again and assign the values from the parameters.
Note: The Azure Pipelines editor shows the loop underlined and reports an error “The first property must be task”.
But when running validate.
The result is OK. Hopefully this issue will get resolved in the future and not show as an error in the UI.
So the loop worked and provided all of the variables to be substituted. We could leave it there as it works, but we could also use some of the other parameter properties such as displayName and values to provide a nicer configuration.
Now I can run this pipeline and see if it was successful.
And I can check the ACR in Azure to confirm the image has successfully been created.
Define the Web App
Now I have the image uploaded to the ACR, I need to define the Azure Web App that I will be deploying to.
For this I will use an ARM (Azure Resource Manager) template.
"description": "The unique name of your Web Site."
"description": "The name of the container image for this web app"
"description": "The name of the azure container registry that contains the webapp"
"description": "The user name to access the azure container registry"
"description": "The password to access the azure container registry"
"hostingPlanName": "[concat('hpn-', parameters('siteName'))]",
"linuxFxVersion": "[concat('DOCKER|', parameters('appImageName'))]",
There are few things to note in this template, firstly that we are deploying to a linux container so the website configuration is a little different to normal. The kind property needs to include more information than just app.
And the reserved property must be set to true.
There are also a couple of settings that aren’t really documented in the Microsoft Docs to configure the app settings to connect to the ACR to retrieve the image. Adding these appSettings will setup the connection.
You may have noticed in the pipeline that I used “Jobs” and created a single job, this could be seen as unnecessary, but now I am going to add another job that will run in parallel with the Build Job.
So I need to add some tasks to build my UI tests. I’ve also added a variable “vmWindowsImageName” as for this job I am going to use a windows image. The test project is .NET Core 3.1 so I will use the DotNetCoreCLI tasks to restore packages and build the tests.
Now the pipeline builds and publishes the necessary artifacts to the pipeline and the ACR, I can now add a new stage to deploy the application.
This new stage uses a special job, a ‘deployment’ job and uses a strategy. The Microsoft Docs have a lot of information about different strategies, for this I will use the ‘runonce’ strategy as the other strategies are not supported here.
- stage: Staging
displayName: Deploy to Staging
- deployment: DeployWeb
displayName: Deploy Web App
siteLocation: UK South
With the job and strategy configured, I can now add the first step to execute the ARM template and create the Web App.
Builds a web application image and uploads it to an ACR
Deploys an Azure Web App using an ARM Template
Deploys the image into the Azure Web App
And runs UI tests against the newly deployed application
This is great but I would guess most of us don’t just have one environment that we need to deploy to and will need at least another one and maybe a manual intervention step too.
To create another environment I could just copy and paste the ‘Staging’ stage, rename it and update the variables. Whilst this approach would work, it would introduce a maintenance overhead we don’t want.
Fortunately Azure Pipelines YAML includes Templates for variables, jobs, steps and stages to handle this.
So, I will move the steps for the ‘Staging’ deployment into a template and call it web-deploy-steps.yml. The template file will look like:
Now the pipeline has ran, let’s check the results.
And let’s see if the resources were deployed into Azure.
Approvals and Checks
If the stage needs a manual intervention or approval step you can configure them in Azure Pipelines, just select ‘Environments’.
Once the list of environments is displayed you can select the one you need to add approvals and checks to e.g. Production.
Selecting the 3 dots on the right hand side and then selecting ‘Approvals and checks’ will allow a variety of options to be added.
There are a number of checks that can be added, here I will just select approvals.
Approvals simply need the users or groups that can approve the stage you want to control.
There are a few more settings for approvals, how many need to approve, approval timeout, etc. but I am not going to go into detail about them.
Azure Pipelines YAML provides a flexible way to create build and deployment pipelines that can be source controlled. Changes can be approved, tracked and are visible to everyone instead of a change via a UI that goes unnoticed and difficult to track if there is a problem caused by a change.
Being able to control the full application deployment flow this way is very powerful and allows the whole team to understand how their application is built and deployed.