Control Deployments using Release Gates
Estimated time: 75 minutes
You will learn how to configure deployment gates and use them to control the execution of Azure Pipelines. You'll configure a release definition with two environments for an Azure Web App, deploying to the DevTest environment only when there are no blocking bugs, and marking the DevTest environment complete only when there are no active alerts in Application Insights.
Before you start
You need:
- Microsoft Edge or an Azure DevOps supported browser
- Azure subscription: You need an active Azure subscription or can create a new one
- Azure DevOps organization: Create one at Create an organization or project collection if you don't have one
- Account permissions: You need a Microsoft account or Microsoft Entra account with:
- Owner role in the Azure subscription
- Global Administrator role in the Microsoft Entra tenant
- For details, see List Azure role assignments using the Azure portal and View and assign administrator roles in Azure Active Directory
About release gates
A release pipeline specifies the end-to-end release process for an application to be deployed across various environments. Deployments to each environment are fully automated using jobs and tasks. It's a best practice to expose updates in a phased manner - expose them to a subset of users, monitor their usage, and expose them to other users based on the experience of the initial set.
Approvals and gates enable you to take control over the start and completion of deployments in a release. You can wait for users to approve or reject deployments manually with approvals. Using release gates, you can specify application health criteria to be met before the release is promoted to the following environment.
Gates can be added to an environment in the release definition from the pre-deployment conditions or the post-deployment conditions panel. Multiple gates can be added to ensure all inputs are successful for the release.
There are 4 types of gates included by default:
- Invoke Azure Function: Trigger execution of an Azure Function and ensure successful completion
- Query Azure Monitor alerts: Observe configured Azure Monitor alert rules for active alerts
- Invoke REST API: Make a call to a REST API and continue if it returns a successful response
- Query work items: Ensure the number of matching work items returned from a query is within a threshold
Create and configure the team project
First, you'll create an Azure DevOps project for this lab.
-
In your browser, open your Azure DevOps organization
-
Click New Project
-
Give your project the name eShopOnWeb
-
Leave other fields with defaults
-
Click Create
Import the eShopOnWeb Git Repository
Next, you'll import the sample repository that contains the application code.
-
In your Azure DevOps organization, open the eShopOnWeb project
-
Click Repos > Files
-
Click Import a Repository
-
Select Import
-
In the Import a Git Repository window, paste this URL:
https://github.com/MicrosoftLearning/eShopOnWeb.git
-
Click Import
The repository is organized this way:
- .ado folder contains Azure DevOps YAML pipelines
- .devcontainer folder contains setup to develop using containers
- infra folder contains Bicep & ARM infrastructure as code templates
- .github folder contains YAML GitHub workflow definitions
- src folder contains the .NET 8 website used in the lab scenarios
- Go to Repos > Branches
- Hover on the main branch then click the ellipsis on the right
- Click Set as default branch
Configure CI Pipeline
You'll add a YAML build definition to the project.
- Navigate to the Pipelines section
- In the Create your first Pipeline window, click Create pipeline
- On the Where is your code? pane, click Azure Repos Git (YAML)
- On the Select a repository pane, click eShopOnWeb
- On the Configure your pipeline pane, scroll down and select Existing Azure Pipelines YAML File
- In the Selecting an existing YAML File blade, specify:
- Branch: main
- Path: .ado/eshoponweb-ci.yml
- Click Continue to save these settings
- From the Review your Pipeline YAML screen, click Run to start the Build Pipeline
- Wait for the Build Pipeline to complete successfully
- Go to Pipelines > Pipelines and click on the recently created pipeline
- Click on the ellipsis and Rename/move option
- Name it eshoponweb-ci and click Save
Create Azure Resources for the Release Pipeline
You'll create two Azure web apps representing the DevTest and Production environments.
Create two Azure web apps
- From your lab computer, navigate to the Azure Portal
- Sign in with the user account that has the Owner role in your Azure subscription
- In the Azure portal, click the Cloud Shell icon (to the right of the search box)
- If prompted to select either Bash or PowerShell, select Bash
Note: If this is your first time starting Cloud Shell and you see the "You have no storage mounted" message, select your subscription and click "Apply".
-
From the Bash prompt, run this command to create a resource group (replace
<region>
with your preferred Azure region):REGION='<region>' RESOURCEGROUPNAME='az400m03l08-RG' az group create -n $RESOURCEGROUPNAME -l $REGION
-
Create an App service plan:
SERVICEPLANNAME='az400m03l08-sp1' az appservice plan create -g $RESOURCEGROUPNAME -n $SERVICEPLANNAME --sku S1
-
Create two web apps with unique names:
SUFFIX=$RANDOM$RANDOM az webapp create -g $RESOURCEGROUPNAME -p $SERVICEPLANNAME -n RGATES$SUFFIX-DevTest az webapp create -g $RESOURCEGROUPNAME -p $SERVICEPLANNAME -n RGATES$SUFFIX-Prod
Note: Record the name of the DevTest web app. You'll need it later.
Note: If you get an error about the subscription not being registered to use namespace 'Microsoft.Web', run:
az provider register --namespace Microsoft.Web
and wait for registration to complete.
- Wait for the provisioning process to complete and close the Cloud Shell pane
Configure an Application Insights resource
-
In the Azure portal, search for Application Insights and select it from the results
-
On the Application Insights blade, select + Create
-
On the Basics tab, specify these settings:
Setting Value Resource group az400m03l08-RG Name the name of the DevTest web app from the previous task Region the same Azure region where you deployed the web apps -
Click Review + create and then click Create
-
Wait for the provisioning process to complete
-
Navigate to the resource group az400m03l08-RG
-
In the list of resources, click the DevTest web app
-
On the DevTest web app page, in the left menu under Monitoring, click Application Insights
-
Click Turn on Application Insights
-
In the Change your resource section, click Select existing resource
-
Select the newly created Application Insight resource
-
Click Apply and when prompted for confirmation, click Yes
-
Wait until the change takes effect
Create monitor alerts
-
From the same Application Insights menu, select View Application Insights Data
-
On the Application Insights resource blade, under Monitoring, click Alerts
-
Click Create > Alert rule
-
In the Condition section, click See all signals
-
Type Requests and from the results, select Failed Requests
-
In the Condition section, leave Threshold set to Static and validate these defaults:
- Aggregation Type: Count
- Operator: Greater Than
- Unit: Count
-
In the Threshold value textbox, type 0
-
Click Next:Actions
-
Don't make changes in Actions, and define these parameters under Details:
Setting Value Severity 2- Warning Alert rule name RGATESDevTest_FailedRequests Advanced Options: Automatically resolve alerts cleared -
Click Review+Create, then Create
-
Wait for the alert rule to be created successfully
Note: Metric alert rules might take up to 10 minutes to activate.
Configure the Release Pipeline
You'll configure a release pipeline with deployment gates.
Set Up Release Tasks
- From the eShopOnWeb project in Azure DevOps, select Pipelines and then Releases
- Click New Pipeline
- From the Select a template window, choose Azure App Service Deployment under Featured templates
- Click Apply
- In the Stage window, update the default "Stage 1" name to DevTest
- Close the popup window using the X button
- On the top of the page, rename the pipeline from New release pipeline to eshoponweb-cd
- Hover over the DevTest Stage and click the Clone button
- Name the cloned stage Production
Note: The pipeline now contains two stages named DevTest and Production.
- On the Pipeline tab, select the Add an Artifact rectangle
- Select eshoponweb-ci in the Source (build pipeline) field
- Click Add to confirm the selection
- From the Artifacts rectangle, click the Continuous deployment trigger (lightning bolt)
- Click Disabled to toggle the switch and enable it
- Leave all other settings at default and close the pane
Configure DevTest stage
- Within the DevTest Environments stage, click the 1 job, 1 task label
- In the Azure subscription dropdown, select your Azure subscription and click Authorize
- Authenticate using the user account with the Owner role in the Azure subscription
- Confirm the App Type is set to "Web App on Windows"
- In the App Service name dropdown, select the name of the DevTest web app
- Select the Deploy Azure App Service task
- In the Package or Folder field, update the default value to:
$(System.DefaultWorkingDirectory)/**/Web.zip
- Open Application and Configuration Settings and enter this in App settings:
-UseOnlyInMemoryDatabase true -ASPNETCORE_ENVIRONMENT Development
Configure Production stage
- Navigate to the Pipeline tab and within the Production Stage, click 1 job, 1 task
- Under the Tasks tab, in the Azure subscription dropdown, select the Azure subscription you used for the DevTest stage
- In the App Service name dropdown, select the name of the Prod web app
- Select the Deploy Azure App Service task
- In the Package or Folder field, update the default value to:
$(System.DefaultWorkingDirectory)/**/Web.zip
- Open Application and Configuration Settings and enter this in App settings:
-UseOnlyInMemoryDatabase true -ASPNETCORE_ENVIRONMENT Development
- Click Save and in the Save dialog box, click OK
Test the release pipeline
- In the Pipelines section, click Pipelines
- Click the eshoponweb-ci build pipeline and then click Run Pipeline
- Accept the default settings and click Run to trigger the pipeline
- Wait for the build pipeline to finish
Note: After the build succeeds, the release will be triggered automatically and the application will be deployed to both environments.
- In the Pipelines section, click Releases
- On the eshoponweb-cd pane, click the entry representing the most recent release
- Track the progress of the release and verify that deployment to both web apps completed successfully
- Switch to the Azure portal, navigate to the az400m03l08-RG resource group
- Click the DevTest web app, then click Browse
- Verify that the web page loads successfully in a new browser tab
- Repeat for the Production web app
- Close the browser tabs displaying the EShopOnWeb web site
Configure Release Gates
You'll set up Quality Gates in the release pipeline.
Configure pre-deployment gates for approvals
- In the Azure DevOps portal, open the eShopOnWeb project
- In Pipelines > Releases, click eshoponweb-cd and then Edit
- On the left edge of the DevTest Environment stage, click the oval shape representing Pre-deployment conditions
- On the Pre-deployment conditions pane, set the Pre-deployment approvals slider to Enabled
- In the Approvers text box, type and select your Azure DevOps account name
Note: In a real-life scenario, this should be a DevOps Team name alias instead of your own name.
- Save the pre-approval settings and close the popup window
- Click Create Release and confirm by pressing Create
- Notice "Release-2" has been created. Click the "Release-2" link to navigate to its details
- Notice the DevTest Stage is in a Pending Approval state
- Click the Approve button to trigger the DevTest Stage
Configure post-deployment gates for Azure Monitor
- Back on the eshoponweb-cd pane, on the right edge of the DevTest Environment stage, click the oval shape representing Post-deployment conditions
- Set the Gates slider to Enabled
- Click + Add and select Query Azure Monitor Alerts
- In the Query Azure Monitor Alerts section:
- Azure subscription: Select the service connection representing your Azure subscription
- Resource group: Select az400m03l08-RG
- Expand the Advanced section and configure:
- Filter type: None
- Severity: Sev0, Sev1, Sev2, Sev3, Sev4
- Time Range: Past Hour
- Alert State: Acknowledged, New
- Monitor Condition: Fired
- Expand Evaluation options and configure:
- Time between re-evaluation of gates: 5 Minutes
- Timeout after which gates fail: 8 Minutes
- Select On successful gates, ask for approvals
Note: The sampling interval and timeout work together so that gates will call their functions at suitable intervals and reject the deployment if they don't succeed within the timeout period.
- Close the Post-deployment conditions pane
- Click Save and in the Save dialog box, click OK
Test Release Gates
You'll test the release gates by updating the application and triggering a deployment.
Generate alerts and test the release process
- From the Azure Portal, browse to the DevTest Web App resource
- From the Overview pane, notice the URL field showing the web application hyperlink
- Click this link to open the eShopOnWeb web application
- To simulate a Failed Request, add /discount to the URL, which will result in an error since that page doesn't exist
- Refresh this page several times to generate multiple events
- From the Azure Portal, search for Application Insights and select the DevTest-AppInsights resource
- Navigate to Alerts
- There should be at least 1 new alert with Severity 2 - Warning showing up
Note: If no Alert shows up yet, wait another few minutes.
- Return to the Azure DevOps Portal and open the eShopOnWeb Project
- Navigate to Pipelines > Releases and select eshoponweb-cd
- Click the Create Release button
- Wait for the Release pipeline to start and approve the DevTest Stage release action
- Wait for the DevTest release Stage to complete successfully
- Notice how the Post-deployment Gates switches to Evaluation Gates status
- Click the Evaluation Gates icon
- For Query Azure Monitor Alerts, notice an initial failed state
- Let the Release pipeline remain in pending state for the next 5 minutes
- After 5 minutes pass, notice the 2nd evaluation failing again
This is expected behavior, since there's an Application Insights Alert triggered for the DevTest Web App.
Note: Since there's an alert triggered by the exception, Query Azure Monitor gate will fail. This prevents deployment to the Production environment.
- Wait a couple more minutes and validate the status of the Release Gates again
- Within a few minutes after the initial Release Gates check, since the initial Application Insight Alert was triggered with "Fired" action, it should result in a successful Release Gate, allowing deployment to the Production Release Stage
Note: If your gate fails, close the alert in Azure Monitor.
Clean up resources
Remember to delete the resources created in the Azure portal to avoid unnecessary charges:
- In the Azure portal, navigate to the az400m03l08-RG resource group
- Click Delete resource group
- Type the resource group name to confirm deletion
- Click Delete
Summary
In this lab, you configured release pipelines and then configured and tested release gates. You learned how to:
- Configure release pipelines with multiple environments
- Set up pre-deployment approvals for manual control
- Configure post-deployment gates with Azure Monitor alerts
- Test release gates by generating application alerts
- Control deployments based on application health criteria
Release gates enable you to specify application health criteria that must be met before a release is promoted to the following environment, providing automated quality controls in your deployment pipeline.