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.

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
- CI (Continuous Integration): The practice of automating the integration of code changes from multiple developers into a single project.
- Build Agent: The machine or service that runs your build jobs. Azure DevOps offers hosted agents (Microsoft-hosted) and self-hosted agents.
- Build Artifacts: The output of a build, such as compiled code, executables, packages, or documentation.
- YAML Pipelines: Modern, flexible pipelines defined as code in a YAML file, stored alongside your source code.
- Classic Editor Pipelines: Pipelines configured through a graphical user interface in Azure DevOps.
Creating Your First Build Pipeline (YAML)
Let's create a simple build pipeline for a .NET Core application.
1. Prerequisites
- An Azure DevOps organization and project.
- A Git repository with your .NET Core application code.
2. Steps
- Navigate to your Azure DevOps project.
- Go to Pipelines > Pipelines.
- Click New pipeline.
- Select where your code is located (e.g., Azure Repos Git, GitHub).
- Choose your repository.
- Azure DevOps will suggest a template. For a .NET Core app, select the .NET Desktop or .NET template.
- 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:
- Build: Compiling code, running linters.
- Test: Executing unit tests, integration tests, code coverage.
- Package: Creating NuGet packages, Docker images.
- Artifacts: Publishing build outputs.
- Deployment: (Often handled by Release Pipelines, but can be initiated here).
Best Practices
- Keep builds fast: Optimize your build steps and dependencies.
- Use YAML: Define your pipelines as code for version control and reproducibility.
- Secure your secrets: Use Azure Key Vault or pipeline variables for sensitive information.
- Run tests regularly: Ensure code quality and catch regressions early.
- Publish artifacts: Make build outputs easily accessible for subsequent stages or deployments.
- Leverage stages and jobs: Organize complex pipelines logically.
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: