get_build_parameters
Retrieve build parameters from Jenkins by job fullname and build number. Returns a dictionary of parameter names and values; omitting number fetches the last build.
Instructions
Get the parameters of 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 dictionary of build parameter names and their values
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fullname | Yes | ||
| number | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp_jenkins/server/build.py:104-118 (handler)MCP tool handler function 'get_build_parameters' decorated with @mcp.tool(tags=['read']). Takes a Jenkins context, job fullname, and optional build number. If number is None, it fetches the last build number. Delegates to jenkins(ctx).get_build_parameters().
@mcp.tool(tags=['read']) async def get_build_parameters(ctx: Context, fullname: str, number: int | None = None) -> dict: """Get the parameters of 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 dictionary of build parameter names and their values """ if number is None: number = jenkins(ctx).get_item(fullname=fullname, depth=1).lastBuild.number return jenkins(ctx).get_build_parameters(fullname=fullname, number=number) - Core implementation method 'get_build_parameters' on the Jenkins REST client class. Parses the fullname into folder/name, makes a GET request to the BUILD_PARAMETERS endpoint, and extracts parameters from the 'actions' array in the JSON response, returning a dict of name->value pairs.
def get_build_parameters(self, *, fullname: str, number: int) -> dict: """Get the build parameters of a specific build. Args: fullname: The fullname of the job. number: The build number. Returns: A dictionary representing the build parameters. """ folder, name = self._parse_fullname(fullname) response = self.request( 'GET', rest_endpoint.BUILD_PARAMETERS(folder=folder, name=name, number=number), ) for action in response.json().get('actions', []): if 'parameters' in action: return {p['name']: p.get('value') for p in action['parameters']} return {} - REST endpoint definition 'BUILD_PARAMETERS' as a RestEndpoint string template. Maps to the Jenkins API URL: '{folder}job/{name}/{number}/api/json?tree=actions[parameters[name,value]]'.
BUILD_PARAMETERS = RestEndpoint('{folder}job/{name}/{number}/api/json?tree=actions[parameters[name,value]]') - Test for 'get_build_parameters' handler. Mocks the Jenkins client and asserts the handler correctly returns the parameters dictionary.
@pytest.mark.asyncio async def test_get_build_parameters(mock_jenkins, mocker): mock_jenkins.get_item.return_value.lastBuild.number = 1 mock_jenkins.get_build_parameters.return_value = {'BRANCH': 'main', 'DEBUG': True} assert await build.get_build_parameters(mocker.Mock(), fullname='job1') == { 'BRANCH': 'main', 'DEBUG': True, }