Azure DevOps works with Azure Policy to add security and governance checks to your release process. First, you create or manage policies in the Azure portal that can restrict deployments to specific regions, require logging, or enforce other compliance rules. In Azure Pipelines, you add a pre-deployment or post-deployment condition using the Check Azure Policy compliance task, which acts as a gate that stops the deployment if any policies are violated.
When the pipeline runs, the AzurePolicyCheckGate task checks whether the resources being deployed follow your organization's policies. If a violation is found, the deployment fails and logs an error showing exactly which policy was broken. You can watch these logs on the Releases page in Azure DevOps to see what needs fixing. This automated approach catches problems before they reach production, reduces manual checking, and helps meet regulatory requirements.
To keep your gates effective, update your Azure Policies regularly as new threats and compliance standards emerge. Use Azure's built-in sample policies for common scenarios like requiring encryption or restricting locations. Set up alerts so your team knows right away when critical violations occur.
Testing in Azure Pipelines follows a sequence from fast, simple checks to slower, more complex ones. Unit tests run first, checking individual functions or components using frameworks like MSTest or xUnit. These tests run quickly and in isolation, making them ideal for frequent execution during every build. They form the first line of defense by catching problems with specific pieces of code.
Integration tests come next, verifying that different parts of your application work together correctly. These tests run against real dependencies like databases or APIs in a staging environment that mirrors production. The pipeline handles the order: it deploys the application and its dependencies first, then runs the integration tests, and finally reports the results. This step catches bugs that only appear when services interact.
Load tests assess how your application performs under heavy user traffic. Using Azure Load Testing, you can generate high load against your application, often in a staging environment, to find bottlenecks like slow database queries or insufficient compute resources. The pipeline publishes results showing response times and error rates. You typically run load tests before major releases to confirm the system can handle expected peak loads.
The complete testing strategy moves through sequential stages: a build stage runs unit tests, a deployment stage sets up staging, an integration test stage validates service interactions, and a load test stage checks performance. Each stage depends on the previous one succeeding, creating a quality gate that stops bad code from moving forward.
Test tasks are predefined actions that tell the pipeline what tests to run and how to run them. You add these tasks through the Azure Pipelines interface by selecting your test framework (such as NUnit, xUnit, or MSTest) and pointing to your test files. The pipeline runs these tasks after the build completes but before any deployment begins, ensuring that faulty code never reaches production.
Test agents are the virtual machines or containers that actually execute your tests. Azure provides hosted agents that are already configured and ready to use, which works well for most projects. For projects with special requirements, you can set up self-hosted agents with specific software and tools that match your application's needs. Agent pools organize these agents together, and you assign capabilities to each agent so the pipeline sends the right tests to the right machines.
Once tests finish running, the results become visible to the team through Azure DevOps dashboards showing pass/fail rates, error details, and trends over time. You can generate reports from these results to share with stakeholders who need visibility into quality metrics. The pipeline can also trigger automated actions when tests fail, such as sending email notifications or blocking deployments until issues are resolved.
To verify that tests thoroughly check your application code, you set up coverage collection within your CI/CD pipeline. Developers integrate tools like Coverlet, OpenCover, or Visual Studio Test directly into the Azure Pipelines build definition. These tools monitor code execution during test runs and record which lines of code are executed. The workflow begins when a build agent compiles the code, runs the test suite through the chosen tool, and outputs raw coverage data that gets converted into readable reports attached to the build summary.
Coverage thresholds define the minimum allowed percentage of code that automated tests must execute. These thresholds focus on metrics like line, branch, or method coverage and are configured within your build pipeline settings. When the pipeline runs, the system compares actual coverage percentages against these predefined targets, providing an immediate measure of test thoroughness for every code change.
After a build completes, detailed coverage reports appear in the Azure DevOps interface. Developers use these reports to find specific classes, methods, or logic branches that lack test coverage. Reviewing these gaps helps write targeted tests for critical, high-risk areas. Tracking these metrics over time shows whether code quality is improving or declining across releases.
Quality gates automatically protect the main code branch by evaluating coverage results before allowing the pipeline to proceed. If the coverage percentage falls below the configured threshold, the quality gate fails the build. This prevents untested or buggy code from moving forward in the deployment process, ensuring only validated changes reach downstream environments.
Seeking the thrill of transformative tech? Explore the art of designing and implementing DevOps solutions on Azure. Master the shift towards CI/CD, testing, and delivery, while preparing for the Designing and Implementing Microsoft DevOps Solutions exam!
Prepare and test your skills

Prepare and test your skills

Azure Pipelines integrates with Azure Policy through the Check Azure Policy compliance task, which functions as a pre-deployment or post-deployment gate to stop releases that violate compliance rules. When the pipeline runs, this task checks deployed resources against policies created in the Azure portal, such as regional deployment restrictions or logging requirements. If a violation is detected, the deployment fails and logs error details on the Releases page to show which policy was broken.
The testing sequence in Azure Pipelines moves from unit tests during the build stage, to staging deployment, to integration tests validating service interactions, and finally to load tests checking performance. This progression organizes testing from fast, isolated checks to slower, more complex evaluations. Each stage depends on the prior stage succeeding, functioning as a quality gate that prevents defective code from moving forward.
Hosted agents are Azure-provided virtual machines or containers that are preconfigured and ready to use, whereas self-hosted agents are customized with specific software and tools to meet specialized project requirements. Both types of agents are organized into agent pools to manage execution environments. Pipelines use capabilities assigned to each agent to ensure test tasks are routed to the appropriate machines.
Quality gates enforce code coverage in Azure Pipelines by automatically failing the build if test coverage percentages fall below predefined thresholds. These thresholds measure line, branch, or method coverage gathered by tools such as Coverlet, OpenCover, or Visual Studio Test during test runs. Failing the build when targets are not met prevents untested or defective code from merging into the main branch or reaching downstream environments.