Skip to main content
Glama

trigger-pipeline

Automatically trigger Azure DevOps build pipelines using definition ID or name, specifying source branch and custom parameters. Simplifies CI/CD workflows for multiple projects and organizations.

Instructions

Trigger a build pipeline in Azure DevOps

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
definitionIdNoBuild definition ID to trigger
definitionNameNoBuild definition name (alternative to ID)
parametersNoPipeline parameters as key-value pairs
sourceBranchNoSource branch to build (default: default branch)

Implementation Reference

  • The primary handler function that executes the 'trigger-pipeline' tool. It queues a new build in Azure DevOps using the REST API, resolving definition by ID or name, handling source branch and parameters, and returning build details.
    * Trigger a build pipeline in Azure DevOps */ private async triggerPipeline(args: any): Promise<any> { try { let definitionId = args.definitionId; // If definition name is provided instead of ID, look up the ID if (!definitionId && args.definitionName) { const definitions = await this.makeApiRequest('/build/definitions?api-version=7.1'); const definition = definitions.value.find((def: any) => def.name.toLowerCase() === args.definitionName.toLowerCase() ); if (!definition) { throw new Error(`Build definition '${args.definitionName}' not found`); } definitionId = definition.id; } if (!definitionId) { throw new Error('Either definitionId or definitionName must be provided'); } // Prepare the build request const buildRequest: any = { definition: { id: definitionId } }; // Add source branch if specified if (args.sourceBranch) { buildRequest.sourceBranch = args.sourceBranch.startsWith('refs/') ? args.sourceBranch : `refs/heads/${args.sourceBranch}`; } // Add parameters if specified if (args.parameters && typeof args.parameters === 'object') { buildRequest.parameters = JSON.stringify(args.parameters); } const result = await this.makeApiRequest( '/build/builds?api-version=7.1', 'POST', buildRequest ); return { content: [{ type: 'text', text: JSON.stringify({ success: true, build: { id: result.id, buildNumber: result.buildNumber, status: result.status, queueTime: result.queueTime, definition: { id: result.definition.id, name: result.definition.name }, sourceBranch: result.sourceBranch, url: result._links?.web?.href || `${this.currentConfig!.organizationUrl}/${this.currentConfig!.project}/_build/results?buildId=${result.id}`, requestedBy: { displayName: result.requestedBy?.displayName || 'API Request', uniqueName: result.requestedBy?.uniqueName || 'api' } } }, null, 2), }], }; } catch (error) { throw new Error(`Failed to trigger pipeline: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
  • src/index.ts:286-310 (registration)
    Registers the 'trigger-pipeline' tool with the MCP server in the list of available tools, including its description and input schema for validation.
    { name: 'trigger-pipeline', description: 'Trigger a build pipeline in Azure DevOps', inputSchema: { type: 'object', properties: { definitionId: { type: 'number', description: 'Build definition ID to trigger', }, definitionName: { type: 'string', description: 'Build definition name (alternative to ID)', }, sourceBranch: { type: 'string', description: 'Source branch to build (default: default branch)', }, parameters: { type: 'object', description: 'Pipeline parameters as key-value pairs', }, }, }, },
  • The switch case dispatcher in handleToolCall that routes 'trigger-pipeline' tool calls to the specific implementation method.
    case 'trigger-pipeline': return await this.triggerPipeline(args || {});

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/wangkanai/devops-enhanced-mcp'

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