To set up Azure DevOps environment approval, you'll need to create a new environment. This involves specifying the environment details, such as the name, description, and resource group.
In Azure DevOps, an environment is a deployment target, and it's essential to configure it correctly to ensure smooth deployment and testing. You can create an environment from a YAML file or from the Azure DevOps interface.
To create an environment from a YAML file, you'll need to define the environment settings in the file, including the name, description, and resource group. This YAML file will serve as a template for creating the environment.
Once you've created the environment, you'll need to configure the environment approval and validation steps. This involves setting up the approval policies and validation rules to ensure that deployments meet the required standards.
Environment Setup
In Azure DevOps, you can configure an environment to control when and how deployments happen.
You can add approvals to ensure that certain conditions are met before a deployment can proceed.
Branch control allows you to specify which branches are allowed to start a deployment, such as only allowing deployments from the master branch.
Business hours let you set a schedule for when deployments can start, so that they only run during certain times, like 9 am to 5 pm.
This means that if you set your business hours to 9 am to 5 pm, a deployment started at 6 pm won't run until 9 am the next day.
Approval Process
In Azure DevOps, approvals are a crucial step in ensuring that deployments are reviewed and approved before they reach production. You can add approvals in the classic editor pipeline by clicking on the icon on the left side of your task and selecting Pre-deployment approvals.
To add approvals in the classic editor, you need to select the users who are allowed to approve the deployment. These approvers will receive an email to approve the deployment, and once the required approver approves, the task continues.
In YAML pipelines, adding approvals is a bit more work, but still straightforward. You need to create an environment in your Azure DevOps project and add an approval by clicking on Approvals and the config flyout appears. You can add users or groups as your designated Approvers and specify the timeout.
You can manually control when a stage should run using approval and checks. This check is commonly used to control deployments to production environments. To do this, you need to navigate to your project, select Pipelines > Environments, and then select your environment.
Here are the steps to add a new check:
- Select the Approvals and checks tab, and then select the + sign to add a new check.
- Select Approvals, and then select Next.
- Add users or groups as your designated Approvers, and, if desired, provide instructions for the approvers.
- Specify if you want to permit or restrict approvers from approving their own runs, and specify your desired Timeout.
- Select Create when you're done.
Note that the list of users who can review an Approval is fixed at the time approvals & checks start running. That is, changes to the list of users and groups of an approval check done after checks start executing aren't picked up.
Validation and Testing
You can use manual validation to pause and wait for approval, which is useful for validating configuration settings or build packages before starting a computation-intensive job.
Manual validation triggers a UI prompt to review and validate the task, and email addresses listed in notifyUsers receive a notification to approve or deny the pipeline run.
The waitForValidation job pauses the run, allowing you to carefully review and validate the task before proceeding.
Test in YAML Pipeline
In a YAML pipeline, you can test the approval process by running the pipeline and stopping the deployment before the publish to nuget.org task. This will trigger the need for an approver to review the deployment.
To review the deployment, click on Review and then Approve. Once you've approved, the deployment will start.
The approval process is an essential step in ensuring that deployments are thoroughly reviewed before they're released to production.
To add a test environment to your pipeline, you can use the clone environment option in the pipeline view. This will allow you to quickly repeat the steps from the previous environment.
Here are the steps to clone and rename the environment to Test:
- Create a new service endpoint connection to the test resource group in Azure.
- Choose the test resource group for the resource group setting.
- Update the template parameters to the test JSON parameters file.
By following these steps, you can easily set up a test environment in your YAML pipeline and ensure that your deployments are thoroughly tested before they're released to production.
Manual Validation Setup
Manual validation is a useful feature in YAML pipelines that allows you to pause and wait for manual approval. This is especially useful in scenarios where you want to validate configuration settings or build packages before starting a computation-intensive job.
To set up manual validation, you can use the Manual Validation task in your YAML pipeline, which pauses the run and triggers a UI prompt to review and validate the task. The email addresses listed in notifyUsers receive a notification to approve or deny the pipeline run.
You can also add approvals when using YAML pipelines, which involves creating an environment and adding an approval to it. This process is a bit more work, but not complicated.
To create an environment, click on New environment in the Environments section of your Azure DevOps project. If you don't have an environment yet, you can create one by clicking on New environment.
The approval process involves adding yourself as an approver, leaving the timeout at 30 days, and adding instructions to the approvers if desired. Click on Create and the approval gets created.
Sources
- https://programmingwithwolfgang.com/deployment-approvals-yaml-pipeline/
- https://learn.microsoft.com/en-us/azure/devops/pipelines/release/deploy-using-approvals
- https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals
- https://learn.microsoft.com/en-us/azure/devops/pipelines/release/approvals/
- https://www.lunavi.com/blog/azure-devops-projects-adding-an-additional-environment
Featured Images: pexels.com