Setting Up CI/CD Pipelines with Azure DevOps
Learn how to build a complete CI/CD pipeline using Azure DevOps, from code commit to deployment.
Continuous Integration and Continuous Deployment (CI/CD) are essential practices in modern software development. In this guide, I’ll show you how to set up a complete CI/CD pipeline using Azure DevOps.
What is Azure DevOps?
Azure DevOps is a comprehensive set of development tools from Microsoft that includes:
- Azure Repos - Git repositories
- Azure Pipelines - CI/CD pipelines
- Azure Boards - Project management
- Azure Test Plans - Testing tools
- Azure Artifacts - Package management
Prerequisites
Before we begin, make sure you have:
- An Azure DevOps organization
- An Azure subscription
- A sample application to deploy
Creating Your First Pipeline
Step 1: Create a New Pipeline
Navigate to Azure Pipelines in your Azure DevOps project and click “New Pipeline”.
Step 2: Connect Your Repository
Choose your source code repository. Azure DevOps supports:
- Azure Repos Git
- GitHub
- Bitbucket
- Other Git repositories
Step 3: Select a Template
Start from a template or create a blank pipeline. For a Node.js application, use the Node.js template:
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: Build
displayName: 'Build stage'
jobs:
- job: Build
displayName: 'Build job'
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
- publish: $(System.DefaultWorkingDirectory)/dist
artifact: drop
- stage: Deploy
displayName: 'Deploy stage'
condition: succeeded()
jobs:
- job: Deploy
displayName: 'Deploy job'
steps:
- download: current
artifact: drop
- task: AzureWebApp@1
inputs:
azureSubscription: 'Your-Azure-Subscription'
appType: 'webApp'
appName: 'your-app-name'
package: '$(Build.ArtifactStagingDirectory)/*.zip'
Pipeline Concepts
Triggers
Define when your pipeline runs:
trigger:
branches:
include:
- main
- develop
paths:
include:
- src/*
- pipelines/*
Stages
Organize your pipeline into logical phases:
stages:
- stage: Build
- stage: Test
- stage: Deploy
Jobs and Steps
Jobs contain steps that execute sequentially:
jobs:
- job: Linux
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo "Running on Linux"
Adding Quality Checks
Running Tests
- script: npm test
displayName: 'Run tests'
Security Scanning
Add security scanning to catch vulnerabilities early:
- task: WhiteSource@21
inputs:
advancedSettings: 'scanType:dependency'
Deployment Strategies
Environment Approvals
Require approval before deployment:
- environment: 'Production'
approvalCount: 1
approvers:
- user@company.com
Rolling Deployment
For zero-downtime updates:
strategy:
rolling:
maxParallel: 50%
deploy:
steps:
- script: deploy.sh
Best Practices
- Use YAML pipelines - Version control your pipeline configuration
- Keep pipelines fast - Parallelize jobs where possible
- Implement security scanning - Scan early and often
- Use environments - Track deployments across environments
- Monitor pipelines - Set up alerts for failures
Conclusion
Azure DevOps provides a powerful platform for implementing CI/CD. Start simple, add complexity gradually, and always prioritize reliability and security.
For more advanced topics, explore:
Happy automating!