CHAPTER 17
CI/CD with Azure DevOps
Updated: May 15, 2026
25 min read
# CHAPTER 17
CI/CD with Azure DevOps
1. Introduction
If a developer has to manually build a Docker container on their laptop, authenticate with the Azure Portal, and manually run a deployment command every time they fix a bug, human error is inevitable. In modern cloud engineering, deployments must be boring, automated, and mathematically reproducible. In this chapter, we will connect the final piece of the architectural puzzle: Continuous Integration and Continuous Deployment (CI/CD). We will automate the pipeline from a Git commit directly into Azure using Azure DevOps.2. Learning Objectives
By the end of this chapter, you will be able to:- Define Continuous Integration (CI) and Continuous Deployment (CD).
- Understand the role of Azure DevOps Services (Repos, Boards, Pipelines).
-
Author an
azure-pipelines.ymlconfiguration file.
- Understand Pipeline Agents (Microsoft-hosted vs. Self-hosted).
- Automate the deployment of an application to Azure App Service.
3. Beginner-Friendly Explanation
Imagine a car factory.- Manual Deployment (The Old Way): An engineer designs a new engine. They have to walk onto the factory floor, stop the assembly line, remove the old engine by hand, bolt the new one in, and restart the line. It is slow and prone to mistakes.
- CI/CD (The Automated Factory): The engineer drops a blueprint into an inbox (Azure Repos). A robot (Azure Pipelines) instantly detects the blueprint. The robot autonomously builds the engine (Docker build), tests it to ensure it won't explode (Unit Tests), walks onto the factory floor, and seamlessly swaps the engine while the car is still moving (Zero-downtime deployment). The engineer never leaves their desk.
4. The Azure DevOps Suite
Azure DevOps is not just a deployment tool; it is an entire suite of project management tools used by massive enterprises:- Azure Boards: Like Jira or Trello. Used for Agile sprint planning and ticketing.
- Azure Repos: Like GitHub. Unlimited, private Git repository hosting.
- Azure Pipelines: The CI/CD engine that builds and deploys the code.
- Azure Artifacts: A package manager (like npm or NuGet) for sharing internal code libraries securely.
5. The CI/CD Pipeline Flow
A standard Azure pipeline follows this exact sequence:-
1.
Trigger: A developer merges code into the
mainbranch in Azure Repos (or GitHub).
- 2. Azure Pipelines Wakes Up: The webhook triggers the Pipeline.
- 3. Step 1 (Test): Run automated .NET/Node.js unit tests. If they fail, STOP the pipeline.
-
4.
Step 2 (Build): Run
docker buildordotnet publishto package the new code.
- 5. Step 3 (Publish Artifact): Save the compiled code as an "Artifact".
- 6. Step 4 (Deploy): The "Release" stage downloads the Artifact and securely pushes it to Azure App Service or AKS.
6. Anatomy of an azure-pipelines.yml
You define your pipeline steps in a YAML file located in the root of your code repository.
yaml
7. Mini Project: Conceptual Automated Deployment
Let's conceptualize the setup of an automated pipeline.Step-by-Step Overview:
- 1. Ensure your application code is committed to an Azure Repo or a GitHub repository.
-
2.
In Azure DevOps (
dev.azure.com), navigate to Pipelines.
- 3. Click Create Pipeline.
- 4. Connect: Select where your code is (e.g., Azure Repos Git or GitHub).
- 5. Select: Select your specific repository.
- 6. Configure: Azure Pipelines is incredibly smart. It will scan your code, realize it is a Node.js app, and automatically generate a starter YAML file for you!
-
7.
Review: Review the generated
azure-pipelines.ymlfile. Modify the "Deploy" task to point to your existing Azure App Service.
- 8. Click Save and run.
-
9.
The Test: Go to your laptop, change a line of HTML, and
git push origin main. Return to the Azure DevOps portal. You will see your pipeline executing live, successfully updating your live website without a single manual server login!
8. Real-World Scenarios
A financial technology company requires absolute security. They cannot allow developers to deploy code from their laptops. They implement a strict CI/CD pipeline using Azure Pipelines. Developers do not have the RBAC permissions required to update the Production App Service. Only the Service Connection (the invisible identity used by Azure DevOps) has those permissions. To get code into production, a developer must submit a Pull Request, get it approved by a senior engineer, and merge it. The Pipeline takes over, ensuring the deployment is sterile, tested, and perfectly auditable.9. Best Practices
- Deployment Gates: In a true Enterprise Release pipeline, you don't deploy straight to Production. You deploy to a "Staging" environment. Then, you configure a "Pre-deployment Approval Gate". The pipeline literally pauses and sends an email to the QA Manager. The code will not deploy to Production until the manager clicks "Approve".
10. Common Mistakes
- Service Connection Failures: When Azure DevOps reaches the "Deploy" step, it must authenticate to your Azure Subscription. Beginners often struggle with this. You must configure an Azure Resource Manager Service Connection within the DevOps project settings, which securely grants DevOps the RBAC permissions to modify your cloud resources.
11. Exercises
- 1. What is the fundamental security advantage of allowing an Azure Pipeline to handle deployments rather than allowing developers to deploy code from their local laptops?
- 2. Explain the purpose of a "Pre-deployment Approval Gate" in an enterprise release pipeline.
12. FAQs
Q: Should I use Azure DevOps or GitHub Actions? A: Microsoft owns both! If you are starting a brand new, lightweight project, GitHub Actions is the modern standard. However, if you are working in a massive enterprise that requires deep Agile boards, complex release management, and strict corporate governance, Azure DevOps remains the undisputed heavyweight champion.13. Interview Questions
-
Q: Detail the architectural flow of a Continuous Deployment pipeline from a developer's
git pushto a live application update on Azure App Service, specifically highlighting the role of the Service Connection.
- Q: Explain the difference between Continuous Integration (CI) and Continuous Deployment (CD). Provide an example of a task that belongs exclusively in the CI phase versus the CD phase.