DEV Community

Supraja Tangella
Supraja Tangella

Posted on

๐—›๐—ผ๐˜„ ๐—”๐˜‡๐˜‚๐—ฟ๐—ฒ ๐——๐—ฒ๐˜ƒ๐—ข๐—ฝ๐˜€ ๐—›๐—ฎ๐—ป๐—ฑ๐—น๐—ฒ๐˜€ ๐—ฃ๐—ฟ๐—ฒ-๐——๐—ฒ๐—ฝ๐—น๐—ผ๐˜†๐—บ๐—ฒ๐—ป๐˜ ๐—”๐—ฝ๐—ฝ๐—ฟ๐—ผ๐˜ƒ๐—ฎ๐—น๐˜€ ๐—ถ๐—ป ๐—ฌ๐—”๐— ๐—Ÿ ๐—ฃ๐—ถ๐—ฝ๐—ฒ๐—น๐—ถ๐—ป๐—ฒ๐˜€

Have you ever wondered how Azure DevOps knows whether to proceed with deployment in a YAML pipeline?

In real-world projects, especially when deploying to a ๐—ฃ๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป ๐—ฒ๐—ป๐˜ƒ๐—ถ๐—ฟ๐—ผ๐—ป๐—บ๐—ฒ๐—ป๐˜, approvals play a crucial role in maintaining control and preventing accidental releases.

Hereโ€™s what I learned and implemented:

โœ” ๐—ฆ๐˜๐—ฒ๐—ฝ-๐—ฏ๐˜†-๐˜€๐˜๐—ฒ๐—ฝ ๐˜‚๐—ป๐—ฑ๐—ฒ๐—ฟ๐˜€๐˜๐—ฎ๐—ป๐—ฑ๐—ถ๐—ป๐—ด:

  1. Define an environment (e.g., Production) in your YAML pipeline using the environment keyword.
  2. Go to ๐—ฃ๐—ถ๐—ฝ๐—ฒ๐—น๐—ถ๐—ป๐—ฒ๐˜€ โ†’ ๐—˜๐—ป๐˜ƒ๐—ถ๐—ฟ๐—ผ๐—ป๐—บ๐—ฒ๐—ป๐˜๐˜€ โ†’ ๐—ฃ๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป in Azure DevOps.
  3. Set ๐—ฝ๐—ฟ๐—ฒ-๐—ฑ๐—ฒ๐—ฝ๐—น๐—ผ๐˜†๐—บ๐—ฒ๐—ป๐˜ ๐—ฎ๐—ฝ๐—ฝ๐—ฟ๐—ผ๐˜ƒ๐—ฎ๐—น๐˜€ by adding the required approvers.
  4. When the pipeline reaches that stage, Azure DevOps automatically ๐—ฝ๐—ฎ๐˜‚๐˜€๐—ฒs and sends an approval request.
  5. If the request is ๐—ฎ๐—ฝ๐—ฝ๐—ฟ๐—ผ๐˜ƒ๐—ฒ๐—ฑ, the pipeline continues and deploys to Production.
  6. If the request is ๐—ฟ๐—ฒ๐—ท๐—ฒ๐—ฐ๐˜๐—ฒ๐—ฑ, the deployment stops โ€” no manual intervention needed in YAML.

๐Ÿ”ง ๐—ฆ๐—ฎ๐—บ๐—ฝ๐—น๐—ฒ ๐—ฌ๐—”๐— ๐—Ÿ ๐˜€๐—ป๐—ถ๐—ฝ๐—ฝ๐—ฒ๐˜:

stages:

  • stage: ProductionDeployment displayName: 'Deploy to Production' dependsOn: Build environment: 'Production' jobs:
    • deployment: DeployToProd environment: 'Production' strategy: runOnce: deploy: steps: - script: echo "Deploying to Production after approval"

Azure DevOps takes care of checking whether the approver has approved or rejected โ€” you donโ€™t need to write extra logic for this in the YAML file.

๐—›๐—ผ๐˜„ ๐—ฑ๐—ผ ๐˜†๐—ผ๐˜‚ ๐—บ๐—ฎ๐—ป๐—ฎ๐—ด๐—ฒ ๐—ฎ๐—ฝ๐—ฝ๐—ฟ๐—ผ๐˜ƒ๐—ฎ๐—น๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ฑ๐—ฒ๐—ฝ๐—น๐—ผ๐˜†๐—บ๐—ฒ๐—ป๐˜๐˜€ ๐˜๐—ผ ๐—ฃ๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป ๐—ถ๐—ป ๐˜†๐—ผ๐˜‚๐—ฟ ๐—–๐—œ/๐—–๐—— ๐—ฝ๐—ถ๐—ฝ๐—ฒ๐—น๐—ถ๐—ป๐—ฒ๐˜€? ๐——๐—ผ ๐˜†๐—ผ๐˜‚ ๐—ฟ๐—ฒ๐—น๐˜† ๐—ผ๐—ป ๐—ฒ๐—ป๐˜ƒ๐—ถ๐—ฟ๐—ผ๐—ป๐—บ๐—ฒ๐—ป๐˜๐˜€ ๐—ถ๐—ป ๐—”๐˜‡๐˜‚๐—ฟ๐—ฒ ๐——๐—ฒ๐˜ƒ๐—ข๐—ฝ๐˜€ ๐—ผ๐—ฟ ๐—ณ๐—ผ๐—น๐—น๐—ผ๐˜„ ๐—ฎ ๐—ฑ๐—ถ๐—ณ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐˜ ๐—ฎ๐—ฝ๐—ฝ๐—ฟ๐—ผ๐˜ƒ๐—ฎ๐—น ๐—ฝ๐—ฟ๐—ผ๐—ฐ๐—ฒ๐˜€๐˜€?

Top comments (0)