Volume 8 · Chapter 7 — Azure Cloud Architecture & Enterprise DevOps for .NET Engineers

Azure DevOps CI/CD Engineering

Goutham Mayaluri 8 min read .NETC#CI/CDAzure

7.1 Introduction

CI/CD is the automation backbone that lets teams ship frequently, safely, and repeatably. Continuous Integration builds and validates every change; Continuous Delivery/Deployment promotes validated builds through environments to production. The engineering goal is a pipeline where a commit flows to production through automated gates with no manual, error-prone steps - shrinking both the risk and the lead time of change. Azure DevOps and GitHub Actions are the common .NET implementations.

7.2 The Pipeline as a Value Stream

sequenceDiagram
  autonumber
  participant Dev as Developer
  participant Repo as Git (PR)
  participant CI as Build + Test + Scan
  participant Art as Artifact / Image (ACR)
  participant Stg as Staging (auto)
  participant Prod as Production (gated)
  Dev->>Repo: open pull request
  Repo->>CI: trigger validation
  CI-->>Repo: build, unit tests, SAST, dependency scan
  Repo->>Repo: review + branch policies -> merge
  Repo->>CI: build main
  CI->>Art: publish versioned artifact/image
  Art->>Stg: deploy + integration tests
  Stg->>Prod: manual approval / automated gate
  Prod-->>Dev: released (canary -> full)

7.3 Pipelines as Code (YAML)

Defining pipelines in YAML checked into the repository makes them versioned, reviewable, and reproducible - the same discipline as application code. A pipeline declares stages (build, test, deploy), each with jobs and steps, and the file evolves with the code it builds.


trigger: [ main ]

stages:
- stage: Build
  jobs:
  - job: build
    steps:
    - task: UseDotNet@2
      inputs: { version: '9.x' }
    - script: dotnet restore
    - script: dotnet build -c Release --no-restore
    - script: dotnet test -c Release --collect:"XPlat Code Coverage"
    - task: Docker@2
      inputs:
        command: buildAndPush
        repository: payments-api
        containerRegistry: acr-connection
        tags: '$(Build.BuildId)'

- stage: DeployStaging
  dependsOn: Build
  jobs:
  - deployment: staging
    environment: 'staging'      # environment can carry approval checks
    strategy:
      runOnce:
        deploy:
          steps:
          - script: az containerapp update -n payments -g rg --image acr.azurecr.io/payments-api:$(Build.BuildId)

7.4 Continuous Integration Practices

Strong CI restores dependencies, compiles, runs fast unit tests, checks code quality and coverage, and runs security scans - all on every pull request, gated by branch protection so nothing merges without passing. Keeping CI fast (parallelism, caching, test impact analysis) is essential, because a slow pipeline erodes the fast-feedback benefit that justifies it.

7.5 Deployment Strategies

Because most incidents are change-induced, how you deploy is a reliability control. Blue-green keeps two production environments and swaps traffic after validation for instant rollback. Canary exposes the new version to a small traffic slice while automated checks compare it to baseline before full rollout. Feature flags decouple deploying code from enabling behavior, so risky features can be turned on gradually or killed instantly without a redeploy.

7.6 Artifact and Environment Management

Build an artifact (or container image) once and promote that same immutable artifact through environments - never rebuild per environment, which invites drift. Store packages in Azure Artifacts and images in Azure Container Registry, versioned and scanned. Environment-specific configuration is injected at deploy time from Key Vault and App Configuration, not baked into the artifact.

7.7 Security in the Pipeline (Shift Left)

Shifting security “left” means catching issues early in the pipeline: dependency/ SCA scanning for vulnerable packages, SAST for code flaws, secret scanning to catch committed credentials, container image scanning, and IaC scanning. Pipelines themselves must be secured - use workload identity/service connections instead of stored credentials, least-privilege service principals, and protected environments with approvals.

Senior Interview Question

Why should pipelines be defined as code?

Because a pipeline is critical infrastructure and deserves the same rigor as application code. Storing it as YAML in the repository gives it version history (you can see who changed the build and why, and revert), code review (pipeline changes go through pull requests and branch policies), and reproducibility (the pipeline that built a past release is recorded alongside that code). It also enables reuse through templates, keeps the pipeline in sync with the code it builds since they evolve together, and removes the fragility and lack of auditability of click-configured pipelines. Pipeline-as-code turns your delivery process into a reviewed, versioned, repeatable asset.

Senior Interview Question

Why build an artifact once and promote it, rather than rebuilding per environment?

Because rebuilding per environment destroys the guarantee that what you tested is what you ship. Every build can differ subtly - a dependency version, a compiler, a timestamp - so a fresh build for production is technically a different, untested artifact even from identical source. Building once and promoting the same immutable artifact (or image) through staging to production means the exact bits you validated are the bits that go live, and only configuration changes between environments, injected at deploy time. This eliminates “works in staging, breaks in prod” drift, makes releases traceable to a specific artifact version, and enables reliable rollback to a known-good build. Configuration, not code, should vary across environments.

Senior Interview Question

Compare blue-green, canary, and feature flags.

All reduce deployment risk but differently. Blue-green runs two full production environments; you deploy to the idle one, validate, then switch all traffic at once, giving instant rollback by switching back - simple and fast but you briefly run double capacity and shift everyone together. Canary releases the new version to a small percentage of traffic, monitors error/latency against baseline, and gradually increases if healthy - it limits blast radius and catches problems real traffic reveals, at the cost of running two versions simultaneously. Feature flags operate at the code level, decoupling deployment from release: you deploy code dark and toggle behavior on for cohorts or off instantly, enabling gradual rollout and kill switches without redeploying. They compose well - deploy via blue-green or canary, then control specific features with flags.

Senior Interview Question

What does "shift left" on security mean in a CI/CD context?

Shifting left means moving security checks earlier - into the pipeline and even the developer’s workflow - instead of leaving them to a late, separate audit. Concretely that is dependency/SCA scanning for vulnerable packages, static analysis (SAST) for insecure code, secret scanning to block committed credentials, container image scanning, and IaC scanning, all running automatically on pull requests and blocking merges when they fail. The payoff is that vulnerabilities are caught when they are cheapest to fix and before they reach production, and security becomes a continuous, automated part of delivery rather than a bottleneck at the end. It also means securing the pipeline itself with least-privilege service connections and no stored credentials.

Principal Engineer Question

How do you design an enterprise CI/CD platform that dozens of teams can use safely and consistently?

I build a paved road: shared, templated pipelines that encode the organization’s standards - build, test, mandatory security scans, artifact publishing, and gated deployments - so teams inherit best practice by using the template rather than each reinventing (and mis-implementing) it. Governance lives in the platform: protected environments with required approvals for production, branch policies enforcing review and passing checks, and least-privilege service connections using workload identity so no long-lived credentials sit in pipelines. I standardize build-once-promote, immutable artifacts in ACR/Azure Artifacts, and configuration injected from Key Vault per environment. Deployment strategies (canary/blue-green) and rollback are built into the templates, and everything is observable so we can measure DORA metrics (lead time, deploy frequency, change-fail rate, MTTR) and improve. The principle is centralized guardrails with team self-service - teams move fast on a governed platform instead of hand-rolling insecure, inconsistent pipelines.

Principal Engineer Question

A team's pipeline takes 45 minutes and developers batch changes to avoid it, hurting quality. How do you fix it?

A slow pipeline defeats the fast-feedback purpose of CI and pushes teams toward large, risky batches, so I treat speed as a first-class reliability concern. I’d profile the pipeline to find the time sinks, then attack them: parallelize independent jobs and test suites, cache dependencies and build outputs, and split the pipeline so fast unit tests and critical checks gate the PR while slower integration/e2e and heavy scans run asynchronously or on a schedule against main. Test impact analysis can run only the tests affected by a change. Flaky tests, which cause reruns, get quarantined and fixed. I’d right-size and scale build agents so queuing is not the bottleneck. The target is a PR pipeline that returns in a few minutes so developers integrate small changes continuously, with comprehensive but non-blocking validation running in the background - restoring the tight feedback loop that makes CI valuable and encourages small, safe changes.

7.8 Banking Enterprise Scenario

A bank standardizes delivery on templated Azure DevOps YAML pipelines. Every pull request builds, runs unit tests with coverage, and passes SAST, dependency, secret, and container scans before branch policies allow a merge. The main build produces a single versioned, signed image in ACR that is promoted unchanged through staging - where integration tests run - to production, which is a protected environment requiring approval. Production rollout is a canary on AKS with automated metric comparison and instant rollback, and risky features hide behind flags. Pipelines authenticate to Azure with workload identity and least-privilege service connections, so no credentials are stored. The platform team owns the templates, giving every team a secure, fast, consistent paved road.

Chapter Revision Notes

  • Automate commit-to-production through gated pipelines to cut risk and lead time.
  • Define pipelines as versioned, reviewed YAML in the repo.
  • Build the artifact once and promote it immutably; vary only configuration.
  • Use canary/blue-green and feature flags to de-risk change.
  • Shift security left: SCA, SAST, secret, image, and IaC scanning on every PR.
  • Provide a templated paved road with guardrails for many teams; keep pipelines fast.