Overview
Azure Pipelines is a cloud service that supports CI/CD to build, test, and deploy your code to any platform. It works with any language, any platform, and any cloud.
- Fully hosted or self‑hosted agents
- Parallel jobs and matrix builds
- Integration with GitHub, Azure Repos, Bitbucket, and more
Getting Started
Follow these steps to create your first pipeline:
- Navigate to your Azure DevOps project.
- Select Pipelines → Create Pipeline.
- Choose the repository source (e.g., Azure Repos Git).
- Select Starter pipeline or configure a
azure-pipelines.ymlfile. - Save and run the pipeline.
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo Hello, Azure Pipelines!
displayName: 'Run a one-line script'
YAML Basics
Azure Pipelines uses a YAML syntax to declare the pipeline structure. Key concepts:
trigger– defines branches that automatically start a run.pr– defines pull‑request validation triggers.stages,jobs,steps– hierarchical execution units.pool– agent specification.
stages:
- stage: Build
jobs:
- job: Compile
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/*.csproj'
- stage: Test
dependsOn: Build
jobs:
- job: UnitTests
steps:
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: '**/*Tests.dll'
Built‑in Tasks
Azure Pipelines provides over 150 built‑in tasks. Below is a quick reference for the most common ones.
| Task | Purpose | Typical Use |
|---|---|---|
DotNetCoreCLI@2 | Run .NET Core commands | Restore, build, test, publish |
NodeTool@0 | Install a specific Node.js version | Build JavaScript projects |
CopyFiles@2 | Copy files to a target folder | Prepare artifacts |
PublishBuildArtifacts@1 | Publish artifacts for release pipelines | Share binaries, packages |
Variables & Secrets
Variables can be defined at pipeline, stage, or job level. Secrets are stored securely.
variables:
buildConfiguration: 'Release'
npmVersion: '8.x'
steps:
- task: Npm@1
inputs:
command: 'install'
workingDir: '$(Build.SourcesDirectory)'
env:
NODE_AUTH_TOKEN: $(npmToken) # secret variable
Triggers
Control when pipelines run using trigger, pr, and schedule.
# Trigger on any push to main or develop
trigger:
branches:
include:
- main
- develop
# PR validation only for feature/* branches
pr:
branches:
include:
- feature/*
# Nightly build at 02:00 UTC
schedules:
- cron: '0 2 * * *'
displayName: Nightly Build
branches:
include:
- main
always: true
Deployments
Deploy to Azure, Kubernetes, or any target using release pipelines or multi‑stage YAML.
stages:
- stage: Deploy
dependsOn: Test
jobs:
- deployment: WebApp
environment: 'prod'
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
inputs:
azureSubscription: 'MySubscription'
appName: 'my-webapp'
package: '$(Pipeline.Workspace)/drop/**/*.zip'
Best Practices
- Keep pipelines declarative and version‑controlled.
- Use templates to reuse common logic.
- Separate build and release concerns.
- Leverage caching for faster builds.
- Validate pull requests with short‑lived pipelines.
# Example of a reusable template
# templates/build.yml
parameters:
vmImage: 'ubuntu-latest'
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
projects: '**/*.csproj'
# In main pipeline
extends:
template: templates/build.yml
parameters:
vmImage: 'windows-2022'
Reference
For detailed documentation, visit the official Microsoft Docs site.