Skip to main content
Glama

readBuildArtifact

Retrieve content from Jenkins build artifacts like logs, reports, or binaries by specifying job path and artifact location. Supports text or base64 formats for different file types.

Instructions

Read the content of a specific build artifact

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
jobFullNameYesFull path of the Jenkins job
artifactPathYesRelative path to the artifact (e.g., "target/app.jar", "reports/test.xml")
buildNumberNoBuild number (optional, defaults to last build)
formatNoFormat for returning binary files (default: text). Use base64 for binary files.

Implementation Reference

  • The main asynchronous handler function that reads the content of a specific build artifact from Jenkins, handling text or base64 formats, JSON parsing for JSON files, and error cases.
    export async function readBuildArtifact(client, args) {
    	const {
    		jobFullName,
    		artifactPath,
    		buildNumber = null,
    		format = "text",
    	} = args;
    	const jobPath = encodeJobPath(jobFullName);
    	const buildPath = buildNumber || "lastBuild";
    
    	try {
    		// Get the actual build number if using 'lastBuild'
    		let actualBuildNumber = buildNumber;
    		if (!buildNumber) {
    			const buildResponse = await client.get(
    				`/job/${jobPath}/${buildPath}/api/json?tree=number`
    			);
    			if (buildResponse.status === 200) {
    				actualBuildNumber = buildResponse.data.number;
    			} else {
    				throw new Error("Could not determine build number");
    			}
    		}
    
    		const artifactUrl = `/job/${jobPath}/${actualBuildNumber}/artifact/${artifactPath}`;
    		const responseType = format === "base64" ? "arraybuffer" : "text";
    
    		const response = await client.get(artifactUrl, { responseType });
    
    		if (response.status === 200) {
    			let content;
    			const mimeType = getMimeType(artifactPath);
    
    			if (format === "base64") {
    				content = Buffer.from(response.data).toString("base64");
    			} else {
    				content = response.data;
    				const extension = artifactPath.split(".").pop().toLowerCase();
    				if (
    					extension === "json" ||
    					(typeof content === "string" &&
    						content.trim().startsWith("{"))
    				) {
    					try {
    						content = JSON.parse(content);
    					} catch {}
    				}
    			}
    
    			return success("readBuildArtifact", {
    				artifact: {
    					path: artifactPath,
    					buildNumber: actualBuildNumber,
    					mimeType,
    					format,
    					size: response.headers["content-length"] || null,
    					content,
    				},
    			});
    		}
    
    		return failure(
    			"readBuildArtifact",
    			`Artifact not found: ${artifactPath} in build ${actualBuildNumber}`,
    			{ statusCode: response.status }
    		);
    	} catch (error) {
    		if (error.response && error.response.status === 404) {
    			return failure(
    				"readBuildArtifact",
    				`Artifact not found: ${artifactPath}`,
    				{ statusCode: 404 }
    			);
    		}
    		return formatError(error, "readBuildArtifact");
    	}
    }
  • Input schema defining parameters for the readBuildArtifact tool: jobFullName (required), artifactPath (required), buildNumber (optional), format (text or base64).
    inputSchema: {
    	type: "object",
    	properties: {
    		jobFullName: {
    			type: "string",
    			description: "Full path of the Jenkins job",
    		},
    		artifactPath: {
    			type: "string",
    			description:
    				'Relative path to the artifact (e.g., "target/app.jar", "reports/test.xml")',
    		},
    		buildNumber: {
    			type: "integer",
    			description:
    				"Build number (optional, defaults to last build)",
    		},
    		format: {
    			type: "string",
    			enum: ["text", "base64"],
    			description:
    				"Format for returning binary files (default: text). Use base64 for binary files.",
    		},
    	},
    	required: ["jobFullName", "artifactPath"],
    },
  • Registration of the readBuildArtifact tool in the central toolRegistry, including name, description, inputSchema, and reference to the handler function.
    readBuildArtifact: {
    	name: "readBuildArtifact",
    	description: "Read the content of a specific build artifact",
    	inputSchema: {
    		type: "object",
    		properties: {
    			jobFullName: {
    				type: "string",
    				description: "Full path of the Jenkins job",
    			},
    			artifactPath: {
    				type: "string",
    				description:
    					'Relative path to the artifact (e.g., "target/app.jar", "reports/test.xml")',
    			},
    			buildNumber: {
    				type: "integer",
    				description:
    					"Build number (optional, defaults to last build)",
    			},
    			format: {
    				type: "string",
    				enum: ["text", "base64"],
    				description:
    					"Format for returning binary files (default: text). Use base64 for binary files.",
    			},
    		},
    		required: ["jobFullName", "artifactPath"],
    	},
    	handler: readBuildArtifact,
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure but only states the basic action. It doesn't mention authentication requirements, rate limits, error conditions, or what happens with binary vs text files beyond the format parameter. For a read operation that could involve sensitive data or large files, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that efficiently communicates the core function without any wasted words. It's appropriately sized and front-loaded with the essential information, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 4 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what format the content is returned in, how binary files are handled beyond the format parameter, potential size limitations, or authentication requirements. Given the complexity and lack of structured metadata, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all parameters are documented in the schema. The description adds no additional parameter information beyond what's already in the schema descriptions. The baseline of 3 is appropriate when the schema does all the parameter documentation work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('read') and resource ('content of a specific build artifact'), making the tool's function immediately understandable. However, it doesn't differentiate from sibling tools like 'listBuildArtifacts' or 'getBuild', which might cause confusion about when to use this specific read operation versus other artifact-related tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided about when to use this tool versus alternatives like 'listBuildArtifacts' or 'getBuild'. The description only states what it does without context about prerequisites, typical use cases, or comparison to sibling tools, leaving the agent to infer usage scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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