Build Pipelines
This document provides a comprehensive guide to creating, configuring, and managing build pipelines in Azure DevOps.
What is a Build Pipeline?
A build pipeline is a series of automated steps that compile source code, run tests, and produce build artifacts. These artifacts are then typically published for use in downstream deployment (release) pipelines.
Creating a Build Pipeline
You can create build pipelines using either the classic editor or YAML.
YAML Pipelines
YAML pipelines offer a code-based approach, allowing you to store your pipeline definitions alongside your application code. This promotes versioning, reusability, and easier collaboration.
A basic YAML build pipeline structure might look like this:
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add another greet
echo Hello from YAML!
displayName: 'Run a multi-line script'
Classic Editor
The classic editor provides a visual interface for defining your build process. It's suitable for simpler pipelines or for those new to Azure Pipelines.
Key Concepts in Build Pipelines
- Triggers: Events that initiate a pipeline run, such as code commits, pull requests, or scheduled times.
- Agent Pools: Groups of agents (virtual machines or physical servers) that execute your pipeline jobs.
- Tasks: Individual automation steps that perform specific actions, like compiling code, running tests, publishing artifacts, or deploying.
- Jobs: A collection of steps that run on a single agent.
- Stages: A logical grouping of jobs, often representing a distinct phase in the build process (e.g., Build, Test, Package).
- Artifacts: The output of a build, such as compiled binaries, deployment packages, or test results.
Common Build Tasks
- NuGet, npm, Maven, Gradle: For package management and building.
- DotNetCoreCLI: For .NET Core projects.
- MSBuild: For .NET Framework projects.
- Copy Files: To copy files between directories.
- Publish Build Artifacts: To make outputs available for later stages or other pipelines.
- Run PowerShell/Bash/Command Script: For custom scripting.
Best Practices for Build Pipelines
- Automate everything: From code checkout to artifact publishing.
- Keep builds fast: Optimize your build process to reduce wait times.
- Build only once: Produce your artifacts once and promote them through subsequent stages.
- Use YAML: For version control and better collaboration.
- Secure your pipeline: Manage secrets and service connections carefully.
- Integrate tests: Run unit, integration, and other tests as part of your build.