Skip to main content
Glama

triggerBuild

Trigger Jenkins job builds programmatically by specifying job path and optional parameters to automate CI/CD workflows through natural language commands.

Instructions

Trigger a build for a Jenkins job

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
jobFullNameYesFull path of the Jenkins job (e.g., "folder/job-name")
parametersNoBuild parameters (optional)

Implementation Reference

  • The core handler function that implements the triggerBuild tool logic: triggers a Jenkins job build via POST to /build endpoint, handles both regular parameters and file uploads using FormData, extracts queueId from response location header, and returns success/failure with relevant info.
    export async function triggerBuild(client, args) { const { jobFullName, parameters = {} } = args; if (!jobFullName) return failure("triggerBuild", "jobFullName is required"); const jobPath = encodeURIComponent(jobFullName).replace(/%2F/g, "/"); const allowAbsolute = process.env.ALLOW_ABSOLUTE_FILE_PARAMS === "1"; try { const form = new FormData(); const jsonParams = { parameter: [] }; let fileIndex = 0; for (const [key, value] of Object.entries(parameters)) { if (typeof value === "string") { const potentialPath = value; const isAbsolute = path.isAbsolute(potentialPath); const withinCwd = !isAbsolute || potentialPath.startsWith(process.cwd()); const exists = withinCwd && fs.existsSync(potentialPath) && fs.statSync(potentialPath).isFile(); if (exists && (!isAbsolute || allowAbsolute)) { const fileFieldName = `file${fileIndex}`; form.append( fileFieldName, fs.createReadStream(potentialPath), path.basename(potentialPath) ); jsonParams.parameter.push({ name: key, file: fileFieldName, }); fileIndex++; continue; } else if (isAbsolute && !allowAbsolute && exists) { return failure( "triggerBuild", `Absolute file paths are not allowed: ${potentialPath}. Set ALLOW_ABSOLUTE_FILE_PARAMS=1 to override.` ); } } // Regular parameter fallback jsonParams.parameter.push({ name: key, value: String(value) }); } form.append("json", JSON.stringify(jsonParams)); const response = await client.post( `${client.baseUrl}/job/${jobPath}/build`, form, { headers: form.getHeaders(), maxContentLength: Infinity, maxBodyLength: Infinity, } ); if (response.status >= 200 && response.status < 300) { const location = response.headers["location"] || response.headers["Location"]; const queueId = location?.match(/queue\/item\/(\d+)/)?.[1] || null; return success("triggerBuild", { message: `Build triggered successfully for ${jobFullName}`, queueUrl: location || null, queueId, statusCode: response.status, }); } return failure( "triggerBuild", `Build trigger returned status ${response.status}`, { statusCode: response.status, data: response.data } ); } catch (error) { return formatError(error, "triggerBuild"); } }
  • Tool registration in toolRegistry object, defining name, description, inputSchema for validation, and references the imported handler function. Used by getAllTools() for MCP server registration.
    triggerBuild: { name: "triggerBuild", description: "Trigger a Jenkins job build with file and regular parameters", inputSchema: { type: "object", properties: { jobFullName: { type: "string", description: 'Jenkins job name (e.g., "PlaywrightBDD")', }, parameters: { type: "object", description: "Build parameters including file paths", additionalProperties: true, }, }, required: ["jobFullName", "parameters"], }, handler: triggerBuild, },
  • Input schema definition for triggerBuild tool, specifying required jobFullName (string) and optional parameters object.
    inputSchema: { type: "object", properties: { jobFullName: { type: "string", description: 'Jenkins job name (e.g., "PlaywrightBDD")', }, parameters: { type: "object", description: "Build parameters including file paths", additionalProperties: true, }, }, required: ["jobFullName", "parameters"], },

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/umishra1504/Jenkins-mcp-server'

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