Validating Azure Pipeline Changes When modifying Azure DevOps pipeline files (YAML files in build/azure-pipelines/), you can validate changes locally using the Azure CLI before committing. This avoids the slow feedback loop of pushing changes, waiting for CI, and checking…
When modifying Azure DevOps pipeline files (YAML files in build/azure-pipelines/), you can validate changes locally using the Azure CLI before committing. This avoids the slow feedback loop of pushing changes, waiting for CI, and checking results.
Prerequisites
Check if Azure CLI is installed:
bash
az --version
If not installed, install it:
bash
# macOS
brew install azure-cli
# Windows (PowerShell as Administrator)
winget install Microsoft.AzureCLI
# Linux (Debian/Ubuntu)
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
Check if the DevOps extension is installed:
bash
az extension show --name azure-devops
If not installed, add it:
bash
az extension add --name azure-devops
Authenticate:
bash
az login
az devops configure --defaults organization=https://dev.azure.com/monacotools project=Monaco
# Queue a build on the current branch
node .github/skills/azure-pipelines/azure-pipeline.ts queue
# Queue with a specific source branch
node .github/skills/azure-pipelines/azure-pipeline.ts queue --branch my-feature-branch
# Queue with custom parameters
node .github/skills/azure-pipelines/azure-pipeline.ts queue --parameter "VSCODE_BUILD_WEB=false" --parameter "VSCODE_PUBLISH=false"
# Parameter value with spaces
node .github/skills/azure-pipelines/azure-pipeline.ts queue --parameter "VSCODE_BUILD_TYPE=Product Build"
Important: Before queueing a new build, cancel any previous builds on the same branch that you no longer need. This frees up build agents and reduces resource waste:
bash
# Find the build ID from status, then cancel it
node .github/skills/azure-pipelines/azure-pipeline.ts status
node .github/skills/azure-pipelines/azure-pipeline.ts cancel --build-id <id>
node .github/skills/azure-pipelines/azure-pipeline.ts queue
Script Options
Option
Description
--branch <name>
Source branch to build (default: current git branch)
--definition <id>
Pipeline definition ID (default: 111)
--parameter <entry>
Pipeline parameter in KEY=value format (repeatable); use this when the value contains spaces
--parameters <list>
Space-separated parameters in KEY=value KEY2=value2 format; values must not contain spaces
# Get status of the most recent builds
node .github/skills/azure-pipelines/azure-pipeline.ts status
# Get overview of a specific build by ID
node .github/skills/azure-pipelines/azure-pipeline.ts status --build-id 123456
# Watch build status (refreshes every 30 seconds)
node .github/skills/azure-pipelines/azure-pipeline.ts status --watch
# Watch with custom interval (60 seconds)
node .github/skills/azure-pipelines/azure-pipeline.ts status --watch 60
Script Options
Option
Description
--build-id <id>
Specific build ID (default: most recent on current branch)
--branch <name>
Filter builds by branch name (shows last 20 builds for branch)
--reason <reason>
Filter builds by reason: manual, individualCI, batchedCI, schedule, pullRequest
--definition <id>
Pipeline definition ID (default: 111)
--watch [seconds]
Continuously poll status until build completes (default: 30s)
# Cancel a build by ID (use status command to find IDs)
node .github/skills/azure-pipelines/azure-pipeline.ts cancel --build-id 123456
# Dry run (show what would be cancelled)
node .github/skills/azure-pipelines/azure-pipeline.ts cancel --build-id 123456 --dry-run
Script Options
Option
Description
--build-id <id>
Build ID to cancel (required)
--definition <id>
Pipeline definition ID (default: 111)
--dry-run
Print what would be cancelled without executing
Testing Pipeline Changes
When the user asks to test changes in an Azure Pipelines build, follow this workflow:
Queue a new build on the current branch
Poll for completion by periodically checking the build status until it finishes
Polling for Build Completion
Use a shell loop with sleep to poll the build status. The sleep command works on all major operating systems:
bash
# Queue the build and note the build ID from output (e.g., 123456)
node .github/skills/azure-pipelines/azure-pipeline.ts queue
# Poll every 60 seconds until complete (works on macOS, Linux, and Windows with Git Bash/WSL)
# Replace <BUILD_ID> with the actual build ID from the queue command
while true; do
node .github/skills/azure-pipelines/azure-pipeline.ts status --build-id <BUILD_ID> --json 2>/dev/null | grep -q '"status": "completed"' && break
sleep 60
done
# Check final result
node .github/skills/azure-pipelines/azure-pipeline.ts status --build-id <BUILD_ID>
Alternatively, use the built-in --watch flag which handles polling automatically:
bash
node .github/skills/azure-pipelines/azure-pipeline.ts queue
# Use the build ID returned by the queue command
node .github/skills/azure-pipelines/azure-pipeline.ts status --build-id <BUILD_ID> --watch
Note: The --watch flag polls every 30 seconds by default. Use --watch 60 for a 60-second interval to reduce API calls.
Common Workflows
1. Quick Pipeline Validation
bash
# Make your YAML changes, then:
git add -A && git commit -m "test: pipeline changes"
git push origin HEAD
# Check for any previous builds on this branch and cancel if needed
node .github/skills/azure-pipelines/azure-pipeline.ts status
node .github/skills/azure-pipelines/azure-pipeline.ts cancel --build-id <id> # if there's an active build
# Queue and watch the new build
node .github/skills/azure-pipelines/azure-pipeline.ts queue
node .github/skills/azure-pipelines/azure-pipeline.ts status --watch
2. Investigate a Build
bash
# Get overview of a build (shows stages, artifacts, and log IDs)
node .github/skills/azure-pipelines/azure-pipeline.ts status --build-id 123456
# Download a specific log for deeper inspection
node .github/skills/azure-pipelines/azure-pipeline.ts status --build-id 123456 --download-log 5
# Download an artifact
node .github/skills/azure-pipelines/azure-pipeline.ts status --build-id 123456 --download-artifact unsigned_vscode_cli_win32_x64_cli
# First, find the build ID
node .github/skills/azure-pipelines/azure-pipeline.ts status
# Cancel a specific build by ID
node .github/skills/azure-pipelines/azure-pipeline.ts cancel --build-id 123456
# Dry run to see what would be cancelled
node .github/skills/azure-pipelines/azure-pipeline.ts cancel --build-id 123456 --dry-run
5. Iterate on Pipeline Changes
When iterating on pipeline YAML changes, always cancel obsolete builds before queueing new ones:
bash
# Push new changes
git add -A && git commit --amend --no-edit
git push --force-with-lease origin HEAD
# Find the outdated build ID and cancel it
node .github/skills/azure-pipelines/azure-pipeline.ts status
node .github/skills/azure-pipelines/azure-pipeline.ts cancel --build-id <id>
# Queue a fresh build and monitor
node .github/skills/azure-pipelines/azure-pipeline.ts queue
node .github/skills/azure-pipelines/azure-pipeline.ts status --watch
Troubleshooting
Authentication Issues
bash
# Re-authenticate
az logout
az login
# Check current account
az account show
Extension Not Found
bash
az extension add --name azure-devops --upgrade
Rate Limiting
If you hit rate limits, add delays between API calls or use --watch with a longer interval.