get_build_scripts
Retrieve scripts used in a Jenkins build job. Provide job fullname and optional build number to get scripts from a specific build.
Instructions
Get the scripts used in a specific build in Jenkins
Args: fullname: The fullname of the job number: The number of the build, if None, get the last build
Returns: A list of scripts used in the build
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fullname | Yes | ||
| number | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/mcp_jenkins/server/build.py:39-54 (handler)The main handler for the get_build_scripts tool. Decorated with @mcp.tool(tags=['read']), it accepts a fullname (job path) and optional build number, fetches the build replay data, and returns the list of scripts.
@mcp.tool(tags=['read']) async def get_build_scripts(ctx: Context, fullname: str, number: int | None = None) -> list[str]: """Get the scripts used in a specific build in Jenkins Args: fullname: The fullname of the job number: The number of the build, if None, get the last build Returns: A list of scripts used in the build """ if number is None: number = jenkins(ctx).get_item(fullname=fullname, depth=1).lastBuild.number return jenkins(ctx).get_build_replay(fullname=fullname, number=number).scripts - src/mcp_jenkins/server/build.py:39-39 (registration)The tool is registered via the @mcp.tool(tags=['read']) decorator on the get_build_scripts function. The 'mcp' object is a JenkinsMCP (subclass of FastMCP) instance created in src/mcp_jenkins/server/__init__.py line 30.
@mcp.tool(tags=['read']) - The BuildReplay model defines the return type: a list of strings (scripts) parsed from the Jenkins replay page.
class BuildReplay(BaseModel): scripts: list[str] - The get_build_replay method on the REST client fetches the replay page HTML, parses out textarea elements matching the script name pattern, and returns a BuildReplay object.
def get_build_replay(self, *, fullname: str, number: int) -> BuildReplay: """Get the build replay of a specific build. If you want to get the pipeline source code of a specific build in Jenkins, you can use this method. Args: fullname: The fullname of the job. number: The build number. Returns: The build replay object containing the pipeline scripts. """ folder, name = self._parse_fullname(fullname) response = self.request('GET', rest_endpoint.BUILD_REPLAY(folder=folder, name=name, number=number)) soup = BeautifulSoup(response.text, 'html.parser') scripts = [textarea.text for textarea in soup.find_all('textarea', {'name': re.compile(r'_\..*Script.*')})] return BuildReplay(scripts=scripts) - The BUILD_REPLAY endpoint template used to construct the URL for fetching build replay data.
BUILD_REPLAY = RestEndpoint('{folder}job/{name}/{number}/replay')