Azure Pipelines - CI/CD & Automation
Azure Pipelines provides build automation, release management, and deployment orchestration using YAML pipelines, classic builds, and release definitions.
Build Definitions (Pipelines)
Manage YAML and classic pipeline definitions.
List Build Definitions
GET /{organization}/{project}/_apis/build/definitions?api-version=7.1
Query options:
?name=MyPipeline- Filter by name?$top=50- Limit results?includeAllProperties=true- Include full definition
Get Build Definition
GET /{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=7.1
Create Build Definition
POST /{organization}/{project}/_apis/build/definitions?api-version=7.1
Content-Type: application/json
{
"name": "MyPipeline",
"type": "build",
"quality": "definition",
"description": "Build pipeline for my project",
"repository": {
"id": "{repositoryId}",
"type": "TfsGit",
"name": "MyRepo",
"url": "https://dev.azure.com/{org}/{project}/_git/MyRepo",
"defaultBranch": "refs/heads/main"
},
"process": {
"yamlFilename": "azure-pipelines.yml",
"type": 2
}
}
Update Build Definition
PUT /{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=7.1
Content-Type: application/json
Delete Build Definition
DELETE /{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=7.1
Queuing & Managing Builds
Queue, monitor, and manage build executions.
Queue Build
POST /{organization}/{project}/_apis/build/builds?api-version=7.1
Content-Type: application/json
{
"definition": {
"id": 123
},
"sourceBranch": "refs/heads/main",
"sourceVersion": "{commitId}",
"priority": "normal",
"parameters": "{\"param1\":\"value1\",\"param2\":\"value2\"}"
}
Get Builds
GET /{organization}/{project}/_apis/build/builds?api-version=7.1
Filter options:
?definitions=1,2,3- Specific definitions?buildNumber=MyBuild.123- By build number?branchName=refs/heads/main- By branch?$orderBy=finishTime desc- Sort by finish time?statusFilter=completed,inProgress- By status
Get Specific Build
GET /{organization}/{project}/_apis/build/builds/{buildId}?api-version=7.1
Update Build
PATCH /{organization}/{project}/_apis/build/builds/{buildId}?api-version=7.1
Content-Type: application/json
{
"status": "inProgress",
"keepForever": true,
"retainedByRelease": true
}
Build statuses:
inProgress- Currently runningcompleted- Finishedcancelling- Being cancelledpostponed- Queued
Stop/Cancel Build
PATCH /{organization}/{project}/_apis/build/builds/{buildId}?api-version=7.1
Content-Type: application/json
{
"status": "cancelling"
}
Delete Build
DELETE /{organization}/{project}/_apis/build/builds/{buildId}?api-version=7.1
Build Logs & Artifacts
Access build logs, timelines, and artifacts.
Get Build Logs
GET /{organization}/{project}/_apis/build/builds/{buildId}/logs?api-version=7.1
Each log entry includes:
- Log ID
- Log file URL
Get Specific Log
GET /{organization}/{project}/_apis/build/builds/{buildId}/logs/{logId}?api-version=7.1
Get Build Timeline
Timeline shows task execution sequence and duration:
GET /{organization}/{project}/_apis/build/builds/{buildId}/timeline?api-version=7.1
Get Build Artifacts
GET /{organization}/{project}/_apis/build/builds/{buildId}/artifacts?api-version=7.1
Response includes artifact names and download URLs:
{
"value": [
{
"id": 1,
"name": "drop",
"resource": {
"downloadUrl": "..."
}
}
]
}
Release Management
Manage release definitions and deployments.
Note: Release endpoints use vsrm.dev.azure.com instead of dev.azure.com
List Release Definitions
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=7.1
Get Release Definition
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=7.1
Create Release Definition
POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=7.1
Content-Type: application/json
{
"name": "MyRelease",
"description": "Release definition",
"environments": [
{
"name": "Development",
"deployPhases": [],
"environmentOptions": {}
}
],
"artifacts": [
{
"type": "Build",
"alias": "drop",
"definitionReference": {
"definition": {
"id": "{buildDefinitionId}"
}
}
}
]
}
Releases (Deployments)
Create and manage release instances.
Create Release
POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=7.1
Content-Type: application/json
{
"definitionId": 1,
"description": "Release triggered from API",
"artifacts": [
{
"alias": "drop",
"instanceReference": {
"id": "{buildId}"
}
}
]
}
Get Releases
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=7.1
Filter options:
?definitionId=1- By definition?statusFilter=active,draft- By status?$orderBy=modifiedOn desc- Sort by modified date
Get Specific Release
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=7.1
Update Release
PATCH https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=7.1
Content-Type: application/json
{
"status": "active"
}
Environment & Deployment Management
Manage release environments and deployments.
Get Release Environment
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}/environments/{environmentId}?api-version=7.1
Update Release Environment
Deploy to or manage an environment:
PATCH https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}/environments/{environmentId}?api-version=7.1
Content-Type: application/json
{
"status": "inProgress",
"scheduledDeploymentTime": "2025-01-15T10:00:00Z"
}
Environment statuses:
notStarted- PendinginProgress- Currently deployingsucceeded- Successfulpartiallysucceeded- Some tasks failedfailed- Failedcanceled- Cancelled
Approvals
Manage release approvals.
Get Approvals
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/approvals?api-version=7.1
Filter options:
?releaseId={releaseId}- By release?statusFilter=pending,approved- By status
Update Approval
PATCH https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/approvals/{approvalId}?api-version=7.1
Content-Type: application/json
{
"status": "approved",
"comments": "Approved - ready for deployment"
}
Approval statuses:
pending- Awaiting approvalapproved- Approvedrejected- Rejectedreassigned- Reassigneddeferred- Deferred
Agent Pools & Management
Manage build and release agents.
List Agent Pools
GET /{organization}/_apis/distributedtask/pools?api-version=7.1
Get Specific Pool
GET /{organization}/_apis/distributedtask/pools/{poolId}?api-version=7.1
Create Agent Pool
POST /{organization}/_apis/distributedtask/pools?api-version=7.1
Content-Type: application/json
{
"name": "MyPoolName",
"autoProvision": false
}
List Agents in Pool
GET /{organization}/_apis/distributedtask/pools/{poolId}/agents?api-version=7.1
Get Specific Agent
GET /{organization}/_apis/distributedtask/pools/{poolId}/agents/{agentId}?api-version=7.1
Update Agent
PATCH /{organization}/_apis/distributedtask/pools/{poolId}/agents/{agentId}?api-version=7.1
Content-Type: application/json
{
"enabled": true
}
Variable Groups & Pipeline Variables
Manage variables across pipelines.
List Variable Groups
GET /{organization}/{project}/_apis/distributedtask/variablegroups?api-version=7.1
Get Variable Group
GET /{organization}/{project}/_apis/distributedtask/variablegroups/{groupId}?api-version=7.1
Create Variable Group
POST /{organization}/{project}/_apis/distributedtask/variablegroups?api-version=7.1
Content-Type: application/json
{
"name": "MyVariableGroup",
"description": "Shared variables",
"variables": {
"var1": {
"value": "value1"
},
"secretVar": {
"value": "secretValue",
"isSecret": true
}
}
}
Update Variable Group
PUT /{organization}/{project}/_apis/distributedtask/variablegroups/{groupId}?api-version=7.1
Content-Type: application/json
{
"id": {groupId},
"name": "UpdatedName",
"variables": {...}
}
Task Groups & Reusable Components
Create reusable task groups for pipeline composition.
List Task Groups
GET /{organization}/{project}/_apis/distributedtask/taskgroups?api-version=7.1
Get Task Group
GET /{organization}/{project}/_apis/distributedtask/taskgroups/{taskGroupId}?api-version=7.1
Service Endpoints (Connections)
Manage service connections for deployment targets.
List Service Endpoints
GET /{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=7.1
Get Service Endpoint
GET /{organization}/{project}/_apis/serviceendpoint/endpoints/{endpointId}?api-version=7.1
Create Service Endpoint
POST /{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=7.1
Content-Type: application/json
{
"name": "MyAzureSubscription",
"type": "azurerm",
"url": "https://management.azure.com/",
"authorization": {
"parameters": {
"tenantId": "{tenantId}",
"clientId": "{clientId}",
"clientSecret": "{clientSecret}",
"subscriptionId": "{subscriptionId}",
"subscriptionName": "My Subscription"
},
"scheme": "ServicePrincipal"
},
"isShared": false
}
Common endpoint types:
azurerm- Azure Resource Managergithub- GitHubkubernetes- Kubernetesdocker- Docker Registrynpm- npm Registrynuget- NuGet
Best Practices
Pipeline Design
- Use YAML pipelines for version control
- Keep pipelines simple and focused
- Use templates for reusable components
- Implement proper branching strategies
- Use meaningful pipeline names
- Document parameters and variables
CI/CD Workflow
- Build on every commit to main
- Run tests automatically
- Gate production deployments with approvals
- Implement blue-green or canary deployments
- Monitor and alert on deployment failures
- Keep deployment logs for audit
- Automate rollback procedures
Security
- Use managed identities where possible
- Store secrets in Key Vault
- Limit agent access to sensitive resources
- Use separate pools for different environments
- Implement PAT rotation
- Audit and log all deployments
- Use service principals with minimal permissions
Performance & Cost
- Use hosted agents for standard workloads
- Self-host agents for long-running builds
- Cache dependencies
- Parallelize builds
- Clean up old build artifacts
- Monitor agent pool utilization
- Use demand-based agent scaling
Monitoring & Troubleshooting
- Check build logs for errors
- Review pipeline execution timeline
- Monitor agent status and health
- Track build duration trends
- Set up alerts for failures
- Use diagnostic logs
- Test locally before committing