7.5 YAML Environments, Checks & Deployment Approvals

Key Takeaways

  • Environments record deployment history per target and are the only construct that supports approvals and checks in YAML pipelines.
  • Approvals require a named human or group; branch control restricts which branches may deploy; business hours windows restrict when.
  • An Invoke REST API or Invoke Azure Function check calls an external system and can poll for a decision, which is how change-management systems gate a release.
  • The exclusive lock check serialises deployments to one environment, preventing two rapid releases from racing into the same target.
  • Checks run before the deployment job is dispatched, so a failed check consumes no agent time and leaves no partial deployment.
Last updated: September 2026

7.5 YAML Environments, Checks & Deployment Approvals

Variables configure a deployment; environments govern it. A YAML environment is the named deployment target that carries approvals, automated checks and deployment history, and its checks are evaluated before any agent is dispatched.

1. YAML Environments: Anatomy and Targets

An Environment is a logical collection of physical or virtual resources that can be targeted by deployments (e.g., development, staging, production). Environments are created under Pipelines → Environments.

Why Use YAML Environments?

  1. Deployment History & Auditing: Tracks every pipeline run, commit, and work item deployed to that specific target environment over time.
  2. Resource Modeling: Environments can map directly to:
    • Kubernetes: Directly links to AKS clusters and namespaces, allowing teams to visualize pod health, container images, and workload statuses directly in the Azure DevOps portal.
    • Virtual Machines: Installs the Azure Pipelines agent directly on Linux or Windows VMs, grouping them into deployment pools for rolling in-place updates.
    • Generic / PaaS: Logical endpoints representing Azure App Services, Azure Functions, or serverless infrastructure.
  3. Decoupled Governance: Critical release gates (approvals, business hours, automated checks) are configured on the Environment in the portal, meaning pipeline authors cannot bypass or disable checks by modifying the YAML file in the repository.
# Targeting an Environment in a Deployment Job
- stage: DeployProd
  displayName: 'Production Deployment'
  jobs:
    - deployment: DeployApp
      displayName: 'Deploy Microservice'
      pool:
        vmImage: 'ubuntu-latest'
      environment: 'production.billing-api' # <EnvironmentName>.<ResourceName>
      strategy:
        runOnce:
          deploy:
            steps:
              - script: echo "Deploying to production billing-api workload..."

2. Environment Approvals and Automated Checks Matrix

Checks and approvals allow organizations to specify criteria that must be satisfied before a stage targeting an environment is permitted to execute. When a deployment job requests an environment, execution pauses, no agent compute is consumed, and the configured checks are evaluated.

Comprehensive Environment Checks Matrix

Check TypeExecution ModePurpose & Evaluation MechanicsCommon AZ-400 Exam Scenario
Manual ApprovalsHuman interventionRequires designated users or Entra ID security groups to review and approve the release. Supports timeout limits and "Prevent approver from deploying their own runs" (Four-Eyes Principle).Production releases requiring explicit sign-off from Release Managers or QA leads.
Branch ControlAutomated policyVerifies that the code being deployed originates only from approved branches (e.g., refs/heads/main, refs/heads/release/*).Preventing developers from deploying experimental feature branches directly to staging or production.
Business HoursAutomated schedulingRestricts deployments to predefined operational time windows (e.g., Monday through Friday, 09:00–17:00 UTC). If triggered outside, execution waits until the window opens.Enforcing deployments during normal business hours when on-call engineers are available to monitor for incidents.
Invoke REST APIAutomated external gateCalls an external REST API endpoint (e.g., ServiceNow, Jira, custom compliance service) and parses the response to verify approval status.Integrating with enterprise Change Advisory Boards (CAB) to verify that an approved change ticket exists before deploying.
Invoke Azure FunctionAutomated serverless gateInvokes a serverless Azure Function with pipeline execution metadata to perform complex validation logic.Executing custom pre-deployment health checks, automated security verification, or IP address availability checks.
Azure Monitor AlertsAutomated observabilityQueries Azure Monitor to ensure no active alerts (Sev 0, Sev 1, Sev 2) exist on the target infrastructure before proceeding.Ensuring production infrastructure is healthy and not experiencing active incidents before deploying updates.
Required TemplateAutomated structural policyMandates that the pipeline triggering the deployment extends a specified corporate YAML template.Enforcing that all pipelines targeting production inherit corporate security scanning and auditing stages.
Exclusive LockAutomated concurrency controlEnsures that only a single pipeline run can deploy to the target environment at any given time.Preventing concurrent deployments from racing, executing out of order, or conflicting on database migrations.

The Exclusive Lock Check: Preventing Race Conditions

In fast-moving teams with multiple developers merging pull requests, multiple pipeline runs can be triggered in rapid succession. Without concurrency control, Pipeline Run #101 (older commit) might deploy after Pipeline Run #102 (newer commit), resulting in regression.

Configuring the Exclusive Lock check on an environment guarantees sequential, serialized execution. When Run #101 enters the deployment stage, it acquires the exclusive lock on production. Run #102 will wait until Run #101 completes its deployment and releases the lock. Furthermore, Azure Pipelines provides an option to deploy only the latest queued run upon lock release, automatically canceling superseded intermediate runs.


3. Realistic Exam Scenarios & Common Traps

Scenario: Financial Core Banking Compliance Pipeline

Context: Contoso Bank is modernizing their core payment gateway deployment to an Azure Kubernetes Service (AKS) cluster. Banking regulations require:

  1. Zero credentials stored in Azure DevOps.
  2. Deployments to production must only happen from the main branch.
  3. A Change Request in ServiceNow must be in the Approved state.
  4. Deployments must occur between 02:00 and 05:00 UTC to minimize customer impact.
  5. Only one pipeline run may deploy at any time to prevent database schema conflicts.

DevOps Solution Architecture:

  • Configure an Azure Key Vault Linked Variable Group connected via an ARM Service Connection using Workload Identity Federation to securely provide database connection strings and TLS certificates.
  • Define an Environment named Production-AKS.
  • Configure five automated checks on the Production-AKS environment in Azure DevOps Project Settings:
    1. Branch Control: Allowed branches set to refs/heads/main.
    2. Invoke REST API: Configured with a ServiceNow service connection to poll the change ticket status until it returns status: Approved.
    3. Business Hours: Configured for 02:00–05:00 UTC daily.
    4. Exclusive Lock: Enabled to serialize all deployments.
    5. Manual Approvals: Assigned to the Core Banking CAB security group.
  • In the YAML pipeline, target the environment in a deployment job: environment: 'Production-AKS'.

Common Exam Traps to Avoid

  • Trap: Believing environment checks can be configured or bypassed inside YAML. Checks and approvals are managed exclusively through the Azure DevOps web portal under Pipelines → Environments → [Environment] → Approvals and checks. A developer cannot disable an approval gate or REST check by editing the YAML file in Git.
  • Trap: Forgetting to map secret variables in custom scripts. Attempting to call $MY_SECRET in a bash step without defining env: MY_SECRET: $(mySecret) results in an empty variable, causing scripts to fail with authentication errors.
  • Trap: Confusing Exclusive Lock on an Environment with Agent Pool concurrency. Agent pool concurrency limits how many jobs run across your pool. The Exclusive Lock on an Environment specifically serializes deployments to that target resource, regardless of how many parallel agent slots your organization has licensed.
Loading diagram...
Environment Deployment Gate & Approval Verification Sequence
Test Your Knowledge

An e-commerce company experiences occasional release collisions where two rapid merges to the 'main' branch trigger parallel pipeline runs that deploy database schema migrations simultaneously to their Production environment. This causes database deadlocks and deployment failures. Which environment check should the DevOps architect configure on the Production environment to resolve this issue without reducing global agent pool concurrency?

A
B
C
D
Test Your Knowledge

A regulated pharmaceutical enterprise requires that all automated deployments to their GxP-validated Production environment satisfy two mandatory conditions: 1) The deployment must be verified against an external ServiceNow Change Advisory Board (CAB) ticket returning an 'Approved' state, and 2) The deployment cannot be approved or bypassed by the developer who authored the pull request. How should the team configure Azure Pipelines to meet both regulatory requirements?

A
B
C
D