Azure DevOps CI/CD: Getting Started
Introduction π
This guide will walk you through setting up a complete CI/CD pipeline in Azure DevOps, allowing automated building, testing, and deployment of applications.
1οΈβ£ Prerequisites
Before we begin, make sure you have the following:
β An Azure DevOps account (Sign up here)
β Installed Git (Download Git)
β A code repository (GitHub, Azure Repos, or any Git-based repo)
β A basic understanding of CI/CD concepts
2οΈβ£ Setting Up a Repository in Azure DevOps
- Go to Azure DevOps β Navigate to Repos.
- Click “New Repository” and select Git.
- Clone the repository locally:
git clone https://dev.azure.com/your-org-name/your-repo-name/_git/your-repo-name
cd your-repo-name
echo "# Azure DevOps CI/CD" >> README.md
git add .
git commit -m "Initial commit"
git push origin main
3οΈβ£ Creating a CI Pipeline (Continuous Integration)
Azure DevOps uses YAML pipelines for automation.
π Steps to Create a CI Pipeline:
- Navigate to Pipelines β New Pipeline.
- Choose your repository (Azure Repos Git / GitHub / Bitbucket).
- Select YAML as the pipeline type.
- Create a .azure-pipelines.yml file in your repo with the following content:
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseNode@2
inputs:
version: '16.x'
- script: |
npm install
npm run build
displayName: 'Install Dependencies & Build'
- script: |
npm test
displayName: 'Run Tests'
- Save and Run the pipeline.
- Check Pipeline Runs to see the execution logs.
4οΈβ£ Creating a CD Pipeline (Continuous Deployment)
Now, letβs deploy the application using Azure App Service.
π Steps to Set Up CD:
- Navigate to Pipelines β Releases β New Release Pipeline.
- Select Azure App Service Deployment as a task.
- Link it to the build artifact from the CI pipeline.
- Configure Azure subscription and select the target App Service.
- Enable Continuous Deployment trigger (automatically deploy after each successful build).
- Save and Deploy.
5οΈβ£ Automating the Entire Workflow
To ensure fully automated CI/CD, update your .azure-pipelines.yml to include both build and deploy steps:
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseNode@2
inputs:
version: '16.x'
- script: |
npm install
npm run build
displayName: 'Install Dependencies & Build'
- script: |
npm test
displayName: 'Run Tests'
- task: AzureWebApp@1
inputs:
azureSubscription: '<Azure Service Connection>'
appName: '<Your App Name>'
package: '$(Build.ArtifactStagingDirectory)/**/*.zip'
6οΈβ£ Monitoring and Troubleshooting
π Checking Pipeline Status
- Go to Azure DevOps β Pipelines β Select the pipeline β Run History.
- Click on Logs to check errors or warnings. Common Issues & Fixes
Table
| Issue | Solution |
|-------------------------------------------|---------------------------------------------------------|
| Build fails due to missing dependencies | Run npm install before the build step |
| Deployment fails with authentication error| Ensure the service connection is valid |
| Changes not deploying automatically | Enable the Continuous Deployment Trigger in Azure DevOps|