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
| Name | Required | Description | Default |
|---|---|---|---|
| definitionId | No | Build definition ID to trigger | |
| definitionName | No | Build definition name (alternative to ID) | |
| parameters | No | Pipeline parameters as key-value pairs | |
| sourceBranch | No | Source branch to build (default: default branch) |
Implementation Reference
- src/handlers/tool-handlers.ts:1065-1141 (handler)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', }, }, }, },
- src/handlers/tool-handlers.ts:47-48 (handler)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 || {});