build_run_build
Trigger automated builds in Azure DevOps using specified project and build definition IDs, with optional branch and custom parameters, via PAT-authenticated API.
Instructions
Triggers a new build for a specified definition.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| definitionId | Yes | ID of the build definition to run | |
| parameters | No | Custom build parameters as key-value pairs | |
| project | Yes | Project ID or name to run the build in | |
| sourceBranch | No | Source branch to run the build from. If not provided, the default branch will be used. |
Implementation Reference
- src/tools/builds.ts:269-296 (handler)The handler function that executes the logic for the 'build_run_build' tool, triggering a new pipeline run in Azure DevOps and returning the build report.async ({ project, definitionId, sourceBranch, parameters }) => { const connection = await connectionProvider(); const buildApi = await connection.getBuildApi(); const pipelinesApi = await connection.getPipelinesApi(); const definition = await buildApi.getDefinition(project, definitionId); const runRequest = { resources: { repositories: { self: { refName: sourceBranch || definition.repository?.defaultBranch || "refs/heads/main", }, }, }, templateParameters: parameters, }; const pipelineRun = await pipelinesApi.runPipeline(runRequest, project, definitionId); const queuedBuild = { id: pipelineRun.id }; const buildId = queuedBuild.id; if (buildId === undefined) { throw new Error("Failed to get build ID from pipeline run"); } const buildReport = await buildApi.getBuildReport(project, buildId); return { content: [{ type: "text", text: JSON.stringify(buildReport, null, 2) }], }; }
- src/tools/builds.ts:263-268 (schema)Zod input schema defining parameters for the 'build_run_build' tool.{ project: z.string().describe("Project ID or name to run the build in"), definitionId: z.number().describe("ID of the build definition to run"), sourceBranch: z.string().optional().describe("Source branch to run the build from. If not provided, the default branch will be used."), parameters: z.record(z.string(), z.string()).optional().describe("Custom build parameters as key-value pairs"), },
- src/tools/builds.ts:260-297 (registration)Registration of the 'build_run_build' tool via server.tool(), using the name mapped in BUILD_TOOLS.run_build.server.tool( BUILD_TOOLS.run_build, "Triggers a new build for a specified definition.", { project: z.string().describe("Project ID or name to run the build in"), definitionId: z.number().describe("ID of the build definition to run"), sourceBranch: z.string().optional().describe("Source branch to run the build from. If not provided, the default branch will be used."), parameters: z.record(z.string(), z.string()).optional().describe("Custom build parameters as key-value pairs"), }, async ({ project, definitionId, sourceBranch, parameters }) => { const connection = await connectionProvider(); const buildApi = await connection.getBuildApi(); const pipelinesApi = await connection.getPipelinesApi(); const definition = await buildApi.getDefinition(project, definitionId); const runRequest = { resources: { repositories: { self: { refName: sourceBranch || definition.repository?.defaultBranch || "refs/heads/main", }, }, }, templateParameters: parameters, }; const pipelineRun = await pipelinesApi.runPipeline(runRequest, project, definitionId); const queuedBuild = { id: pipelineRun.id }; const buildId = queuedBuild.id; if (buildId === undefined) { throw new Error("Failed to get build ID from pipeline run"); } const buildReport = await buildApi.getBuildReport(project, buildId); return { content: [{ type: "text", text: JSON.stringify(buildReport, null, 2) }], }; } );
- src/tools/builds.ts:12-22 (registration)Constant mapping internal names to tool names, including 'run_build' to 'build_run_build'.const BUILD_TOOLS = { get_definitions: "build_get_definitions", get_definition_revisions: "build_get_definition_revisions", get_builds: "build_get_builds", get_log: "build_get_log", get_log_by_id: "build_get_log_by_id", get_changes: "build_get_changes", run_build: "build_run_build", get_status: "build_get_status", update_build_stage: "build_update_build_stage", };