This Skill operates within the scope ofproject. Whether a Pipeline definitionorbuild IDis needed depends on the user's question.
Project Selection
-
If the user has provided a project name (for example, "Contoso project"), use it directly and do not call the project list API.
-
If not provided, ask the user to provide it once.
-
If still not provided, list the projects for the user to choose from:
curl -sS -u ":$AZURE_DEVOPS_PAT" \ "https://dev.azure.com/$AZURE_DEVOPS_ORG/_apis/projects?%24top=500&api-version=7.1"
Pipeline Definition Selection
- When the user has provided a Pipeline or definition name, find the definition ID by filtering by name:
curl -sS -u ":$AZURE_DEVOPS_PAT" \
"https://dev.azure.com/$AZURE_DEVOPS_ORG/{project}/_apis/build/definitions?name={name}&api-version=7.1"
Get value[].id and value[].name。name The * wildcard is available (for example, CI*); if multiple are found, ask the user to choose one.
- When the user has not specified a Pipeline and the question requires it (for example, "list recent builds"), ask the user to provide it once.
- If still not provided, call the above API without
nameto list all definitions for the user to choose from.
Connection and Authentication
Always use curl to call the Azure DevOps REST API directly, with authentication parameters included in each command.
- Organization: Read the environment variable
AZURE_DEVOPS_ORG(organization name, for example,contoso). If it is not set, ask the user once; if the user provides a URL, extract the organization name fromhttps://dev.azure.com/{org}orhttps://{org}.visualstudio.com. - Token: Send the PAT with Basic authentication:
-u ":$AZURE_DEVOPS_PAT"; if onlyAZURE_DEVOPS_EXT_PATis set (the variable used by the Azure CLI azure-devops extension), use it instead. When using a Microsoft Entra ID token instead, replace it with-H "Authorization: Bearer $AZURE_DEVOPS_TOKEN". If neither is set, ask the user to setAZURE_DEVOPS_PATin their own terminal and retry, then stop. Read the token only from environment variables: do not ask the user to paste the token into the conversation, and do not print it or write it to a file. - PAT Permission Scopes:Build (Read)、Project and Team (Read)。
- Encoding: URL-encode project and Pipeline names in paths and query strings (write spaces as
%20); in query strings, write$as%24(for example,%24top) to avoid shell expansion. - Errors: HTTP 401, 403, 203, or a response that is an HTML login page means the token is invalid, expired, or has insufficient permissions; report it and stop. HTTP 404 means the organization, project, or build ID is incorrect.
- Windows PowerShell: Call
curl.exe(not thecurlalias); write the environment variable as$env:AZURE_DEVOPS_PAT; PowerShell does not support<<'EOF', so first write the JSON body to a temporary file, then send it with--data-binary "@body.json".
Rules
1. List recent builds for a Pipeline
-
When the user wants tolist buildsorshow recent builds, filter by definition ID:
curl -sS -u ":$AZURE_DEVOPS_PAT" \ "https://dev.azure.com/$AZURE_DEVOPS_ORG/{project}/_apis/build/builds?definitions={definitionId}&%24top=20&queryOrder=queueTimeDescending&api-version=7.1" -
When the user specifies conditions, add filter parameters (for example, "failed builds on main"):
- Branch:
branchName=refs/heads/main - Status:
statusFilter=completed(inProgress、notStarted、cancelling…) - Result:
resultFilter=failed(succeeded、partiallySucceeded、canceled)
- Branch:
-
When the user does not request it, do not fetch logs or changes.
-
Present the results in a table.
-
When there are no builds, explicitly state that this Pipeline has no builds.
Example: "List the recent builds of the Contoso project CI-Main pipeline"
2. Get build status by ID
-
When the user asks abouta specific build(for example, "build 12345"):
curl -sS -u ":$AZURE_DEVOPS_PAT" \ "https://dev.azure.com/$AZURE_DEVOPS_ORG/{project}/_apis/build/builds/{buildId}?api-version=7.1" -
Show the build number, status, result, source branch, start and finish times, requester, and definition name.
-
When the build failed, suggest that the user check the logs.
Example: "What is the status of build 12345 in the Contoso project?"
3. View logs of a failed build
-
When the user wantsto view the logsor askswhy the build failed, first get the build's Timeline and find the failed steps:
curl -sS -u ":$AZURE_DEVOPS_PAT" \ "https://dev.azure.com/$AZURE_DEVOPS_ORG/{project}/_apis/build/builds/{buildId}/timeline?api-version=7.1"In
records[], find records whoseresultisfailed, and prioritize steps whosetypeisTask;issues[]already contains the error summary,log.idis the log ID for that step. -
For each failed step, get the log content (plain text), keeping only the last section:
curl -sS -u ":$AZURE_DEVOPS_PAT" \ "https://dev.azure.com/$AZURE_DEVOPS_ORG/{project}/_apis/build/builds/{buildId}/logs/{logId}?api-version=7.1" | tail -n 200When a specific range is needed, use
&startLine={n}&endLine={m}。 -
Present the log content in a code block for easier reading.
-
Focus on the failed steps and the last section of each log; do not fetch the logs of the other steps.
Example: "Show the logs for build 12345 in the Contoso project", "Why did build 12345 fail?"
4. List the build's changes
-
When the user wantsto view the changesorlist commits :
curl -sS -u ":$AZURE_DEVOPS_PAT" \ "https://dev.azure.com/$AZURE_DEVOPS_ORG/{project}/_apis/build/builds/{buildId}/changes?%24top=50&api-version=7.1" -
Present the commit ID, author, and message in a table.
-
When there are no changes, explicitly state that this build has no associated changes.
Example: "What changes does build 12345 include?", "List the commits for build 12345 in the Contoso project"
Present the results
Display times in the user's local time zone; when the time zone cannot be determined, indicate UTC.
Present the build list in a table with the following columns:
- Build ID: a clickable hyperlink, in the format
[{buildId}](https://dev.azure.com/{organization}/{project}/_build/results?buildId={buildId}) - Definition name(
definition.name) - Status(
status:completed、inProgress、cancelling、notStarted) - Result(
result), plus an emoji: ✅ succeeded, ❌ failed, ⚠️ partiallySucceeded, 🚫 canceled - Source branch(
sourceBranch) - Start time(
startTime, formatYYYY/MM/DD HH:MM) - Requester(
requestedFor.displayName, show only the name)
For the status of a single build, in addition to the above columns, add:
- Finish time(
finishTime, formatYYYY/MM/DD HH:MM) - Build number(
buildNumber) - Duration(calculated from the start and finish times)
Present the change list in a table:
- Commit ID(
idthe first 8 characters of ) - Author(
author.displayName) - Message(
messagefirst line of) - time(
timestamp)