AZ-400 Designing and Implementing Microsoft DevOps Solutions Exam

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!

Practice Test

Intermediate
Exam

Design and implement checks and approvals by using YAML-basedenvironments

Design and Implement Checks and Approvals by Using YAML-Based Environments

Configure Pre-Deployment and Post-Deployment Gates in YAML

YAML pipelines in Azure DevOps allow for advanced configuration of pre-deployment and post-deployment gates to ensure quality, security, and compliance before and after a release. Gates can be automated checks that run scripts or invoke external services, and you can also require approvals from designated reviewers.

Setting Up Service Connections

To configure environment checks and approvals, you first need a service connection:

  1. Sign in to your Azure DevOps organization and navigate to your project.
  2. Create a Service Connection:
    • Go to Project settings > Service connections > New service connection.
    • Choose Azure Resource Manager and follow the prompts to create a connection, usually using an Automatic Service Principal for authentication.

Environment Configuration

Environment types dictate the settings and gated checks applied during deployments. You can define different types such as Sandbox, FunctionApp, and WebApp:

  1. Create environment types at the dev center level and reference them at the project level to ensure consistent control over deployment environments.
  2. Under Projects, configure the specific environment types and assign the necessary subscriptions, identities, and permissions.

YAML Pipeline Configuration

For pre-deployment and post-deployment gates inside a pipeline:

  • Specify the environment resources, approval policies, and gates within the azure-pipelines.yml file.
  • Use scripts or commands defined in steps for tasks like creating an environment, running validations, or executing custom checks before transitioning between stages.

Example setup:

trigger:
- main

stages:
- stage: Deploy
  jobs:
  - deployment: DeployJob
    environment: 'Production'
    strategy:
      runOnce:
        deploy:
          steps:
          - script: echo "Deploying to Production"
            name: DeployStep
          - script: |
              if [[ $(curl -sS http://example.com/health) != "Healthy" ]]; then
                echo "Health check failed!"
                exit 1
              fi
            displayName: 'Pre-deployment gate'
          - script: echo "Finalizing Deployment"
            name: FinalStep

Managing Approvals

To integrate manual intervention in gates, you can configure manual reviewers:

  • Include a checks node in your azure-pipelines.yml specifying the identity of reviewers who need to approve before moving forward.
jobs:
- job: CheckGate
  pool: server
  steps:
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: Write-Host "Running pre-deployment checks"
      checks:
        - script: |
            echo "Approval required"
            echo "Reviewer: $(user.Identity)"

Conclusion

Configuring pre-deployment and post-deployment gates in Azure DevOps using YAML involves setting up service connections, defining environment types, and integrating scripts for automated checks. Ensuring the deployment process complies with security, reliability, and compliance standards ultimately leads to a more robust CI/CD pipeline.