trigger-pipeline
Start Azure DevOps build pipelines using definition IDs, names, or branch specifications to automate software deployment processes.
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) | |
| sourceBranch | No | Source branch to build (default: default branch) | |
| parameters | No | Pipeline parameters as key-value pairs |
Implementation Reference
- src/handlers/tool-handlers.ts:1067-1141 (handler)The core handler function that implements the 'trigger-pipeline' tool. It resolves the build definition ID if a name is provided, constructs the build request with optional source branch and parameters, and triggers the pipeline via a POST to the Azure DevOps builds API.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)MCP tool registration including the tool name, description, and input schema definition returned by the listTools handler.{ 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)Dispatch case in the central handleToolCall method that routes 'trigger-pipeline' calls to the specific triggerPipeline implementation.case 'trigger-pipeline': return await this.triggerPipeline(args || {});