You are here: MSDN Tutorials > Azure > DevOps > Build Pipelines

Azure DevOps Build Pipelines: A Comprehensive Guide

Learn how to create, configure, and manage efficient build pipelines in Azure DevOps to automate your software compilation and testing processes.

Azure DevOps Pipelines Overview

What are Build Pipelines?

A build pipeline in Azure DevOps is a set of automated processes that compile your source code, run tests, and produce build artifacts. These pipelines are crucial for implementing Continuous Integration (CI), a software development practice where developers frequently merge their code changes into a central repository, after which automated builds and tests are run.

Key Concepts

Creating Your First Build Pipeline (YAML)

Let's create a simple build pipeline for a .NET Core application.

1. Prerequisites

2. Steps

  1. Navigate to your Azure DevOps project.
  2. Go to Pipelines > Pipelines.
  3. Click New pipeline.
  4. Select where your code is located (e.g., Azure Repos Git, GitHub).
  5. Choose your repository.
  6. Azure DevOps will suggest a template. For a .NET Core app, select the .NET Desktop or .NET template.
  7. Review the generated azure-pipelines.yml file.

Example azure-pipelines.yml for .NET Core

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: UseDotNet@2
  displayName: 'Use .NET SDK 6.0'
  inputs:
    version: '6.0.x'

- task: DotNetCoreCLI@2
  displayName: 'Restore NuGet packages'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Build project'
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration Release'

- task: DotNetCoreCLI@2
  displayName: 'Run unit tests'
  inputs:
    command: 'test'
    projects: '**/*[Tt]ests/*.csproj'
    arguments: '--configuration Release --logger trx --results-directory $(Agent.TempDirectory)'

- task: PublishTestResults@2
  displayName: 'Publish Test Results'
  inputs:
    testResultsFormat: 'VSTest'
    testResultsFiles: '$(Agent.TempDirectory)/**/*.trx'
    mergeTestResults: true

- task: DotNetCoreCLI@2
  displayName: 'Publish application'
  inputs:
    command: 'publish'
    projects: '**/*.csproj'
    arguments: '--configuration Release --output $(build.artifactstagingdirectory)'
    zipAfterPublish: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifacts'
  inputs:
    pathToPublish: '$(build.artifactstagingdirectory)'
    artifactName: 'drop'

Customizing Your Build Pipeline

You can customize your pipeline by adding or modifying tasks for various operations:

Best Practices

Next Steps

Once your build pipeline is set up, you'll typically want to create a Release Pipeline to automate the deployment of your build artifacts to various environments.

Explore more advanced topics like: