General Build Pipeline (CI) in Azure DevOps

Let’s walk through a general-purpose Azure DevOps build pipeline template that can be applied to most common application types (web apps, APIs, microservices, etc.) using CI/CD best practices, excluding Azure Data Factory (ADF).


๐Ÿ’ก Goal: General Build Pipeline (CI) in Azure DevOps

This applies to:

  • .NET, Java, Node.js, Python apps
  • Microservices with Docker
  • Infrastructure as Code (ARM, Bicep, Terraform)
  • Any codebase where you want to build, test, and publish artifacts

โœ… Key Steps in a General Azure DevOps Build Pipeline

StepStagePurpose
1CheckoutPull latest code from Git
2Restore/Resolve dependenciesInstall NuGet/npm/pip packages
3Compile/BuildCompile source code
4Run Unit TestsEnsure code quality and pass rate
5Code Quality CheckSonarQube, ESLint, etc.
6Package ArtifactsZip, publish output (DLLs, WARs, images)
7Publish Build ArtifactsMake them available for release pipeline
8Optional: Build Docker imageFor containerized apps

๐Ÿงพ Sample Build YAML Templates by Type


๐Ÿ”น 1. .NET Core Web API/Service

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  buildConfiguration: 'Release'

steps:
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '6.x.x'

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
  inputs:
    command: 'test'
    projects: '**/*Tests.csproj'
    arguments: '--configuration $(buildConfiguration) --collect:"Code coverage"'

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: true
    arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'

๐Ÿ”น 2. Node.js Application

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '18.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run build
  displayName: 'Install dependencies and build'

- script: |
    npm test
  displayName: 'Run unit tests'

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)'
    Contents: '**'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'

๐Ÿ”น 3. Dockerized App (Any Language)

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

variables:
  imageName: 'myapp'

steps:
- task: Docker@2
  inputs:
    containerRegistry: '<yourDockerRegistryServiceConnection>'
    repository: '$(imageName)'
    command: 'buildAndPush'
    Dockerfile: '**/Dockerfile'
    tags: |
      $(Build.BuildId)

๐Ÿ”น Use this if you plan to deploy via Kubernetes, Azure Container Apps, or App Services with containers.


๐Ÿ”น 4. Terraform Infrastructure Pipeline

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: TerraformInstaller@1
  inputs:
    terraformVersion: '1.5.x'

- task: TerraformTaskV1@0
  inputs:
    provider: 'azurerm'
    command: 'init'
    backendServiceArm: '<serviceConnection>'
    backendAzureRmResourceGroupName: '<rg>'
    backendAzureRmStorageAccountName: '<storage>'
    backendAzureRmContainerName: 'tfstate'
    backendAzureRmKey: 'terraform.tfstate'

- task: TerraformTaskV1@0
  inputs:
    provider: 'azurerm'
    command: 'validate'

- task: TerraformTaskV1@0
  inputs:
    provider: 'azurerm'
    command: 'plan'

- task: TerraformTaskV1@0
  inputs:
    provider: 'azurerm'
    command: 'apply'
    environmentServiceNameAzureRM: '<serviceConnection>'
    vars: '-var="env=dev"'

๐Ÿง  Tips for General Build Pipelines

TipDescription
๐Ÿ” Secure SecretsUse Azure Key Vault or pipeline secrets
๐Ÿงช Always TestAdd unit and integration tests
๐ŸŽฏ ModularizeKeep reusable scripts in templates (YAML extends)
๐Ÿ”„ ReuseShare artifacts across environments (Dev > QA > Prod)
๐Ÿ”„ Auto-triggerEnable CI triggers or PR validation builds

๐Ÿ“ Typical Build Output (Artifacts)

  • Web app: DLLs, config files, web.config
  • Node app: JS files, dist/ folder
  • Docker: Tagged images in registry
  • Infra: Terraform plan, .tfstate backup

Related Posts

Azure DevOps Interview Questions & Answers

Azure DevOps Interview Questions & Answers 1๏ธโƒฃ Essential (Basic) Questions These test your foundation. 1. What is Azure DevOps?Azure DevOps is Microsoftโ€™s cloud service providing DevOps tools…

Read More

Types of Merge Strategies or Commit Behaviors in Azure Devops

In Azure DevOps (and Git in general), when merging branches, there are several types of merge strategies or commit behaviors beyond just fast-forward. Here’s a breakdown: โœ……

Read More

Kubernetes Certifications in 2025: Which One Should You Choose?

Kubernetes Certifications in 2025: Which One Should You Choose? Kubernetes has become the cornerstone of modern cloud-native application deployment and orchestration. Whether you’re a beginner just diving…

Read More

Top 5 Kubernetes Tools That Will Replace Your Bash Scripts in 2025

๐Ÿš€ Top 5 Kubernetes Tools That Will Replace Your Bash Scripts in 2025 For years, DevOps engineers and platform teams have relied on Bash scripts to automate…

Read More

Kubernetes Horror Stories (and What We Learned From Them)

โ˜ ๏ธ Kubernetes Horror Stories (and What We Learned From Them) Because what doesn’t kill your cluster makes it stronger. Kubernetes is powerful โ€” but with great power…

Read More

Why Your Kubernetes Costs Are Out of Control โ€“ and How to Fix It (2025 Guide)

๐Ÿ’ธ Why Your Kubernetes Costs Are Out of Control โ€“ and How to Fix It (2025 Guide) Kubernetes is powerful โ€” but it isnโ€™t cheap. While it…

Read More
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x