Skip to main content
Glama

stopBuild

Stop a running Jenkins build by specifying the job path and optional build number to halt execution and free resources.

Instructions

Stop/kill a running Jenkins build

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
jobFullNameYesFull path of the Jenkins job
buildNumberNoBuild number to stop (optional, defaults to last build)

Implementation Reference

  • The main handler function for the 'stopBuild' tool. It checks if the specified build is running, attempts a graceful stop via the Jenkins /stop endpoint, and falls back to a forceful kill via /kill if necessary. Handles errors and returns formatted success/failure responses.
    export async function stopBuild(client, args) { const { jobFullName, buildNumber = null } = args; const jobPath = encodeJobPath(jobFullName); const buildPath = buildNumber || "lastBuild"; try { // Get actual build number and check if build is running const buildInfo = await client.get( `${client.baseUrl}/job/${jobPath}/${buildPath}/api/json?tree=number,building,result,url` ); if (buildInfo.status !== 200) { return failure( "stopBuild", `Build not found: ${jobFullName}#${buildPath}`, { statusCode: buildInfo.status } ); } const actualBuildNumber = buildInfo.data.number; const isBuilding = buildInfo.data.building; const buildUrl = buildInfo.data.url; if (!isBuilding) { return failure( "stopBuild", `Build #${actualBuildNumber} is not currently running`, { buildResult: buildInfo.data.result, buildUrl } ); } // Try to stop the build (graceful stop) const stopResponse = await client.post( `${client.baseUrl}/job/${jobPath}/${actualBuildNumber}/stop`, null ); if (isSuccessStatus(stopResponse.status)) { return success("stopBuild", { message: `Build #${actualBuildNumber} stop request sent successfully`, buildNumber: actualBuildNumber, buildUrl, action: "stop", }); } // If stop fails, try kill (forceful termination) const killResponse = await client.post( `${client.baseUrl}/job/${jobPath}/${actualBuildNumber}/kill`, null ); if (isSuccessStatus(killResponse.status)) { return success("stopBuild", { message: `Build #${actualBuildNumber} kill request sent successfully`, buildNumber: actualBuildNumber, buildUrl, action: "kill", }); } return failure( "stopBuild", `Failed to stop build #${actualBuildNumber}`, { statusCode: stopResponse.status } ); } catch (error) { return formatError(error, "stopBuild"); } }
  • The registration of the 'stopBuild' tool in the central toolRegistry. Defines the tool's name, description, input schema (requiring jobFullName, optional buildNumber), and references the handler function.
    stopBuild: { name: "stopBuild", description: "Stop/kill a running Jenkins build", inputSchema: { type: "object", properties: { jobFullName: { type: "string", description: "Full path of the Jenkins job", }, buildNumber: { type: "integer", description: "Build number to stop (optional, defaults to last build)", }, }, required: ["jobFullName"], }, handler: stopBuild, },
  • The input schema for the stopBuild tool, defining the expected parameters: jobFullName (required string) and buildNumber (optional integer). Used for MCP tool validation.
    inputSchema: { type: "object", properties: { jobFullName: { type: "string", description: "Full path of the Jenkins job", }, buildNumber: { type: "integer", description: "Build number to stop (optional, defaults to last build)", }, }, required: ["jobFullName"], },

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