get-pipeline-logs
Azure DevOps Pipeline Log Retrieval
Get logs from Azure DevOps pipeline runs. Always work with the latest run to ensure logs are available (deleted builds have no logs).
Prerequisites
- Azure DevOps organization and project (from deploy.json)
- Pipeline ID (get via
az pipelines list) - Azure CLI for authentication
Complete Workflow: Latest Run Logs
1) Get latest run ID
# Load configuration from deploy.json
$config = Get-Content .github/skills/deploy.json | ConvertFrom-Json
$org = ($config.ADOOrg -replace 'https://dev.azure.com/', '')
$project = $config.ADOProject
$pipelineId = 45 # Replace with your pipeline ID# Get latest run (top 1, newest first)$latestRun = az pipelines runs list ` --org "https://dev.azure.com/$org" ` --project $project ` --pipeline-ids $pipelineId ` --top 1 ` --query-order QueueTimeDesc ` --query "[0]" | ConvertFrom-Json$buildId = $latestRun.idWrite-Host "Latest run: $buildId (Status: $($latestRun.status), Result: $($latestRun.result))"
2) List all logs for the build
3) Download specific log
```powershell$logId = 13 # or get from logs list above$token = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsv$headers = @{ Authorization = "Bearer $token" }$uri = "https://dev.azure.com/$org/$project/_apis/build/builds/$buildId/logs/$logId`?api-version=7.1-preview.2"# Download to fileInvoke-RestMethod -Uri $uri -Headers $headers | Out-File "$env:TEMP\build-$buildId-log-$logId.txt"# Search for errorsGet-Content "$env:TEMP\build-$buildId-log-$logId.txt" | Select-String -Pattern "error|Error|##[error]|failed|Failed" -Context 3
### 4) Download all logs as ZIP
```powershell$token = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsv$headers = @{ Authorization = "Bearer $token" }$uri = "https://dev.azure.com/$org/$project/_apis/build/builds/$buildId/logs?api-version=7.1-preview.2&`$format=zip"Invoke-WebRequest -Uri $uri -Headers $headers -OutFile "$env:TEMP\build-$buildId-logs.zip"Expand-Archive -Path "$env:TEMP\build-$buildId-logs.zip" -DestinationPath "$env:TEMP\build-$buildId-logs" -Force# List largest logsGet-ChildItem "$env:TEMP\build-$buildId-logs" | Sort-Object Length -Descending | Select-Object -First 10
One-Liner: Get Latest Run Logs
$config = Get-Content .github/deploy.json | ConvertFrom-Json
$org = ($config.ADOOrg -replace 'https://dev.azure.com/', '')
$project = $config.ADOProject
$pipelineId = 45$buildId = (az pipelines runs list --org "https://dev.azure.com/$org" --project $project --pipeline-ids $pipelineId --top 1 --query-order QueueTimeDesc --query "[0].id" -o tsv)$token = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsv$logs = Invoke-RestMethod -Uri "https://dev.azure.com/$org/$project/_apis/build/builds/$buildId/logs?api-version=7.1-preview.2" -Headers @{Authorization="Bearer $token"}$largestLog = $logs.value | Sort-Object lineCount -Descending | Select-Object -First 1Invoke-RestMethod -Uri "https://dev.azure.com/$org/$project/_apis/build/builds/$buildId/logs/$($largestLog.id)?api-version=7.1-preview.2" -Headers @{Authorization="Bearer $token"} | Out-File "$env:TEMP\latest-error.txt"Get-Content "$env:TEMP\latest-error.txt" | Select-String "error|Error|##\[error\]" -Context 3
Critical Notes
- Always use latest run:
- Token resource ID:
499b84ac-1321-427f-aa17-267ca6975798is Azure DevOps Entra ID resource - Build vs Run: Terms are interchangeable in Azure DevOps (buildId = runId)
- Configuration: Load org/project from
.github/deploy.json
Troubleshooting
References- Review logs to diagnose pipeline issues: https://learn.microsoft.com/en-us/azure/devops/pipelines/troubleshooting/review-logs- Builds API: https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds## LicenseMIT
More from alexander-kastil/agentic-sw-engineering
net-cli
Master .NET CLI commands for project management. Use when building, testing, running projects, managing NuGet packages, formatting code, configuring solutions, using hot reload with watch mode, or troubleshooting build issues. Covers dotnet build, dotnet test, dotnet run, dotnet format, package management, and solution organization with proper SDK setup.
1create-wi
Automate creation of Azure DevOps workload identity federation service connections with deployment metadata from deploy.json. Use when users need to create or delete Azure service connections with workload identity federation for secure, passwordless authentication.
1angular-http
Implement HTTP data fetching in Angular v20+ using resource(), httpResource(), and HttpClient. Use for API calls, data loading with signals, request/response handling, and interceptors. Triggers on data fetching, API integration, loading states, error handling, or converting Observable-based HTTP to signal-based patterns.
1linkedin-article
Write long-form LinkedIn articles that establish deep thought leadership and drive sustained engagement. Use when creating in-depth content pieces, publishing detailed frameworks, sharing research-backed insights, building authority through comprehensive storytelling, documenting industry trends, or creating evergreen content that drives organic traffic. Covers article structure, depth strategies, SEO optimization, formatting for readability, distribution tactics, and measuring article impact.
1copilot-sdk
Build agentic applications with GitHub Copilot SDK. Use when embedding AI agents in apps, creating custom tools, implementing streaming responses, managing sessions, connecting to MCP servers, or creating custom agents. Triggers on Copilot SDK, GitHub SDK, agentic app, embed Copilot, programmable agent, MCP server, custom agent.
1social-content
Expert social media strategist for content creation and audience building. Use when creating social content strategies, developing content calendars, writing engaging posts, repurposing content across platforms, analyzing social metrics, building personal and company brands, or optimizing engagement. Covers LinkedIn, Twitter/X, Instagram, TikTok, and Facebook with platform-specific strategies, hook formulas, and content pillars framework.
1