trigger_pipeline
Start a pipeline run in Azure DevOps by specifying the pipeline ID, branch, and optional variables to automate build and deployment processes.
Instructions
Trigger a pipeline run
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pipelineId | Yes | Pipeline ID to trigger | |
| branch | No | Branch to run the pipeline on (optional, defaults to default branch) | |
| variables | No | Pipeline variables to override (optional) |
Implementation Reference
- src/tools/pipeline/trigger.ts:11-63 (handler)The core handler function that triggers the Azure DevOps pipeline using the Build API, handling arguments validation, pipeline definition retrieval, build queuing, and error handling.export async function triggerPipeline(args: TriggerPipelineArgs, config: AzureDevOpsConfig) { if (!args.pipelineId) { throw new McpError(ErrorCode.InvalidParams, 'Pipeline ID is required'); } AzureDevOpsConnection.initialize(config); const connection = AzureDevOpsConnection.getInstance(); const pipelineApi = await connection.getBuildApi(); try { // Get pipeline definition first const definition = await pipelineApi.getDefinition( config.project, args.pipelineId ); if (!definition) { throw new McpError( ErrorCode.InvalidParams, `Pipeline with ID ${args.pipelineId} not found` ); } // Create build parameters const build = { definition: { id: args.pipelineId, }, project: definition.project, sourceBranch: args.branch || definition.repository?.defaultBranch || 'main', parameters: args.variables ? JSON.stringify(args.variables) : undefined, }; // Queue new build const queuedBuild = await pipelineApi.queueBuild(build, config.project); return { content: [ { type: 'text', text: JSON.stringify(queuedBuild, null, 2), }, ], }; } catch (error: unknown) { if (error instanceof McpError) throw error; const errorMessage = error instanceof Error ? error.message : 'Unknown error'; throw new McpError( ErrorCode.InternalError, `Failed to trigger pipeline: ${errorMessage}` ); } }
- src/tools/pipeline/index.ts:23-47 (schema)The MCP tool definition including name, description, and inputSchema for validating trigger_pipeline arguments.{ name: 'trigger_pipeline', description: 'Trigger a pipeline run', inputSchema: { type: 'object', properties: { pipelineId: { type: 'number', description: 'Pipeline ID to trigger', }, branch: { type: 'string', description: 'Branch to run the pipeline on (optional, defaults to default branch)', }, variables: { type: 'object', description: 'Pipeline variables to override (optional)', additionalProperties: { type: 'string', }, }, }, required: ['pipelineId'], }, },
- src/tools/pipeline/index.ts:50-57 (registration)Exports the pipeline tools module with initialize function that provides the triggerPipeline handler wrapper and tool definitions.export const pipelineTools = { initialize: (config: AzureDevOpsConfig) => ({ getPipelines: (args: any) => getPipelines(args, config), triggerPipeline: (args: any) => triggerPipeline(args, config), definitions, }), definitions, };
- src/index.ts:163-167 (registration)Registers the tool handler in the main MCP server switch statement, routing 'trigger_pipeline' calls to the pipeline tools instance.case 'trigger_pipeline': result = await tools.pipeline.triggerPipeline( validateArgs(request.params.arguments, 'Pipeline trigger arguments required') ); break;