Skip to main content
Glama

scheduleBuild

Schedule Jenkins builds to run at specific times with optional parameters for automated job execution and workflow management.

Instructions

Schedule a Jenkins build to run at a specific time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
jobFullNameYesFull path of the Jenkins job
parametersNoBuild parameters (optional)
scheduleTimeYesTime to schedule the build (e.g., '22:15', '10:30 PM', or full datetime string)

Implementation Reference

  • The core handler function for the 'scheduleBuild' tool. Parses scheduleTime, handles parameters including file uploads, calculates delay, and posts to Jenkins API to schedule the build.
    export async function scheduleBuild(client, args) { const { jobFullName, parameters = {}, scheduleTime } = args; if (!jobFullName) return failure("scheduleBuild", "jobFullName is required"); if (!scheduleTime) return failure("scheduleBuild", "scheduleTime is required"); const allowAbsolute = process.env.ALLOW_ABSOLUTE_FILE_PARAMS === "1"; let scheduledDate; try { scheduledDate = parseScheduleTime(scheduleTime); } catch (e) { return failure("scheduleBuild", e.message); } const now = new Date(); const delayInSeconds = Math.max( 0, Math.floor((scheduledDate - now) / 1000) ); const jobPath = encodeURIComponent(jobFullName).replace(/%2F/g, "/"); const form = new FormData(); 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)) { form.append( key, fs.createReadStream(potentialPath), path.basename(potentialPath) ); continue; } else if (isAbsolute && !allowAbsolute && exists) { return failure( "scheduleBuild", `Absolute file paths are not allowed: ${potentialPath}` ); } } form.append(key, String(value)); } try { const res = await client.post( `${client.baseUrl}/job/${jobPath}/buildWithParameters?delay=${delayInSeconds}sec`, form, { headers: form.getHeaders(), maxBodyLength: Infinity } ); if (res.status >= 200 && res.status < 300) { return success("scheduleBuild", { status: res.status, queueUrl: res.headers.location, }); } return failure( "scheduleBuild", `Schedule returned status ${res.status}`, { statusCode: res.status } ); } catch (error) { return formatError(error, "scheduleBuild"); } }
  • Input schema definition for the scheduleBuild tool, specifying required parameters: jobFullName, scheduleTime, and optional parameters and description.
    inputSchema: { type: "object", properties: { jobFullName: { type: "string", description: 'Jenkins job name (e.g., "PlaywrightBDD")', }, scheduleTime: { type: "string", description: "When to run the build (e.g., 'in 5 minutes', 'at 3:30 PM', '2024-12-20 15:30')", }, parameters: { type: "object", description: "Build parameters including file paths", additionalProperties: true, }, description: { type: "string", description: "Optional description for the scheduled build", }, }, required: ["jobFullName", "scheduleTime", "parameters"], },
  • Registration of the scheduleBuild tool in the central toolRegistry object, including name, description, inputSchema, and handler reference.
    scheduleBuild: { name: "scheduleBuild", description: "Schedule a Jenkins build with file and regular parameters to run at a specific time", inputSchema: { type: "object", properties: { jobFullName: { type: "string", description: 'Jenkins job name (e.g., "PlaywrightBDD")', }, scheduleTime: { type: "string", description: "When to run the build (e.g., 'in 5 minutes', 'at 3:30 PM', '2024-12-20 15:30')", }, parameters: { type: "object", description: "Build parameters including file paths", additionalProperties: true, }, description: { type: "string", description: "Optional description for the scheduled build", }, }, required: ["jobFullName", "scheduleTime", "parameters"], }, handler: scheduleBuild, },

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