Skip to main content
Glama
ennuiii

Azure DevOps MCP Server with PAT Authentication

by ennuiii

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
NameRequiredDescriptionDefault
definitionIdYesID of the build definition to run
parametersNoCustom build parameters as key-value pairs
projectYesProject ID or name to run the build in
sourceBranchNoSource branch to run the build from. If not provided, the default branch will be used.

Implementation Reference

  • 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) }],
      };
    }
  • 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"),
    },
  • 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) }],
        };
      }
    );
  • 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",
    };
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ennuiii/DevOpsMcpPAT'

If you have feedback or need assistance with the MCP directory API, please join our Discord server