In a microservices architecture, automating the deployment process ensures that changes can be delivered quickly and consistently. Azure DevOps provides a comprehensive set of tools to manage the lifecycle of software development, from code repositories to automated pipelines. This guide will walk through setting up a CI/CD pipeline for two .NET microservices, Product and Order services, demonstrating how to build, test, and deploy them using Azure DevOps.
Setting Up Azure DevOps
- Create an Azure DevOps Organization: Visit Azure DevOps, sign in, and create an organization.
- Create a Project: Within your organization, create a new project to manage your microservices' repositories and pipelines.
Configuring Azure Repos
- Import Repositories: Import your existing Git repositories for the Product and Order services into Azure Repos.
Creating the CI/CD Pipeline
Pipeline Overview
The pipeline consists of several stages, including building, testing, and deploying both microservices. We'll define the pipeline using YAML.
Pipeline Configuration (azure-pipelines.yml)
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
dockerRegistryServiceConnection: 'dockerhub-connection'
dockerRegistry: 'your-dockerhub-username'
productServiceImageName: 'product-service'
orderServiceImageName: 'order-service'
stages:
- stage: Build
jobs:
- job: BuildProductService
displayName: 'Build Product Service'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
- script: dotnet build --configuration $(buildConfiguration) src/ProductService/ProductService.csproj
displayName: 'Build Product Service'
- job: BuildOrderService
displayName: 'Build Order Service'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
- script: dotnet build --configuration $(buildConfiguration) src/OrderService/OrderService.csproj
displayName: 'Build Order Service'
- stage: Test
dependsOn: Build
jobs:
- job: TestProductService
displayName: 'Test Product Service'
steps:
- script: dotnet test --configuration $(buildConfiguration) src/ProductService/ProductService.Tests/ProductService.Tests.csproj
displayName: 'Test Product Service'
- job: TestOrderService
displayName: 'Test Order Service'
steps:
- script: dotnet test --configuration $(buildConfiguration) src/OrderService/OrderService.Tests/OrderService.Tests.csproj
displayName: 'Test Order Service'
- stage: DockerBuildAndPush
dependsOn: Test
jobs:
- job: BuildAndPushProductService
displayName: 'Docker Build and Push Product Service'
steps:
- task: Docker@2
inputs:
containerRegistry: $(dockerRegistryServiceConnection)
repository: $(dockerRegistry)/$(productServiceImageName)
command: 'buildAndPush'
Dockerfile: '**/ProductService/Dockerfile'
tags: |
$(Build.BuildId)
latest
- job: BuildAndPushOrderService
displayName: 'Docker Build and Push Order Service'
steps:
- task: Docker@2
inputs:
containerRegistry: $(dockerRegistryServiceConnection)
repository: $(dockerRegistry)/$(orderServiceImageName)
command: 'buildAndPush'
Dockerfile: '**/OrderService/Dockerfile'
tags: |
$(Build.BuildId)
latest
- stage: Deploy
dependsOn: DockerBuildAndPush
jobs:
- deployment: DeployProductService
displayName: 'Deploy Product Service'
environment: 'product-service-production'
strategy:
runOnce:
deploy:
steps:
- script: echo 'Deploying Product Service to production...'
- deployment: DeployOrderService
displayName: 'Deploy Order Service'
environment: 'order-service-production'
strategy:
runOnce:
deploy:
steps:
- script: echo 'Deploying Order Service to production...'

Join the conversation! Your thoughts help the community grow.