Skip to main content
Glama
xhuaustc

Jenkins MCP Tool

trigger_build

Trigger Jenkins job builds automatically, handling parameter requirements and returning build numbers or queue IDs for CI/CD automation.

Instructions

Trigger Jenkins job build.

Automatically determines parameter requirements and waits to obtain build_number.

Args:
    server_name: Jenkins server name
    job_full_name: Full job name
    params: Optional parameter dict
    ctx: MCP context (for logging)

Returns:
    Dict containing build_number or queue_id

Raises:
    JenkinsParameterError: Missing required parameters
    JenkinsError: Trigger failed

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
server_nameYes
job_full_nameYes
paramsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
statusYes
messageYes
queue_idYes
build_urlYes
queue_urlYes
build_numberYes

Implementation Reference

  • MCP tool handler for 'trigger_build': validates job parameters, handles logging via context, and delegates to Jenkins client.
    @mcp.tool()
    def trigger_build(
        server_name: str, job_full_name: str, params: Any = None, ctx: Context = None
    ) -> TriggerResult:
        """Trigger Jenkins job build.
    
        Automatically determines parameter requirements and waits to obtain build_number.
    
        Args:
            server_name: Jenkins server name
            job_full_name: Full job name
            params: Optional parameter dict
            ctx: MCP context (for logging)
    
        Returns:
            Dict containing build_number or queue_id
    
        Raises:
            JenkinsParameterError: Missing required parameters
            JenkinsError: Trigger failed
        """
        client = JenkinsAPIClient(server_name)
    
        # Parameter type conversion
        build_params: ParameterDict = {}
        if params:
            if isinstance(params, dict):
                build_params = params
            else:
                # Try to convert other types
                try:
                    build_params = dict(params)
                except (TypeError, ValueError):
                    if ctx:
                        ctx.log(
                            "warning",
                            f"Invalid params type: {type(params)}, ignoring parameters",
                        )
                    build_params = {}
    
        # Check required parameters
        job_params = client.get_job_parameters(job_full_name)
        if job_params:
            required_params = [p for p in job_params if p["default"] is None]
            missing_params = []
    
            for param in required_params:
                if not build_params or param["name"] not in build_params:
                    missing_params.append(param)
    
            if missing_params:
                # Build detailed error message
                param_details = []
                for param in missing_params:
                    detail = f"{param['name']} (type: {param['type']}, default: {param['default']}"
                    if param.get("choices"):
                        detail += f", choices: {param['choices']}"
                    detail += ")"
                    param_details.append(detail)
    
                error_msg = f"This job requires required parameters, please provide them before execution. Missing parameters: {', '.join(param_details)}"
                raise JenkinsParameterError(error_msg, [p["name"] for p in missing_params])
    
        if ctx:
            ctx.log("info", f"Triggering build for {job_full_name} on {server_name}")
            if build_params:
                ctx.log("debug", f"Build parameters: {build_params}")
    
        return client.trigger_build(job_full_name, build_params)
  • Low-level JenkinsAPIClient.trigger_build method: performs HTTP POST to Jenkins API to queue the build and waits for it to start.
    def trigger_build(
        self, job_full_name: str, params: Optional[ParameterDict] = None
    ) -> TriggerResult:
        """Trigger build.
    
        Args:
            job_full_name: Full job name
            params: Build parameters
    
        Returns:
            Trigger result
    
        Raises:
            JenkinsError: Trigger failed
        """
        job_url = self._build_job_url(job_full_name)
    
        # Check job parameters
        job_params = self.get_job_parameters(job_full_name)
    
        if job_params:
            # Parameterized build
            build_url = f"{job_url}/buildWithParameters"
            build_params = params or {}
        else:
            # Non-parameterized build
            build_url = f"{job_url}/build"
            build_params = {}
    
        response = self._make_request("POST", build_url, params=build_params)
        response.raise_for_status()
    
        # Get queue location
        queue_location = response.headers.get("Location", "")
        queue_id = None
    
        if queue_location:
            match = re.search(r"/queue/item/(\d+)/", queue_location)
            if match:
                queue_id = int(match.group(1))
    
        # Wait for build to start
        return self._wait_for_build_start(queue_id, queue_location)
  • TypedDict schema defining the return type TriggerResult for the trigger_build tool.
    class TriggerResult(TypedDict):
        """Trigger build result."""
    
        status: Literal["BUILD_STARTED", "QUEUED"]
        build_number: Optional[int]
        build_url: Optional[str]
        queue_id: Optional[int]
        queue_url: Optional[str]
        message: Optional[str]
  • Implicit registration via import of jenkins.tools module (which imports mcp_tools.py) after FastMCP server creation.
    import jenkins.tools  # noqa
    import jenkins.resources  # noqa
    import jenkins.prompts  # noqa
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behaviors: it automatically determines parameter requirements, waits to obtain a build number, and raises specific errors (JenkinsParameterError, JenkinsError). This covers operational traits beyond basic functionality, though it could add more on permissions or rate limits.

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 well-structured and front-loaded with the core purpose, followed by organized sections for Args, Returns, and Raises. Every sentence adds value, such as explaining automatic parameter handling and error conditions, with no wasted words or redundancy.

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

Completeness5/5

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

Given the tool's complexity (triggering builds with parameter handling), no annotations, and an output schema present (so return values are documented), the description is complete enough. It covers purpose, parameters, behaviors, errors, and output, providing sufficient context for effective use without needing to repeat structured data.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It lists all parameters (server_name, job_full_name, params, ctx) and explains their roles (e.g., 'Optional parameter dict', 'MCP context for logging'), adding meaningful context beyond the bare schema. However, it doesn't detail format or examples for params, leaving some gaps.

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

Purpose5/5

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

The description clearly states the action ('Trigger Jenkins job build'), the resource ('Jenkins job'), and distinguishes it from siblings like 'stop_build' or 'get_build_status' by focusing on initiating a build. It specifies the tool automatically determines parameter requirements and waits for a build number, making the purpose specific and differentiated.

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

Usage Guidelines4/5

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

The description implies usage for triggering builds and mentions automatic parameter handling, but does not explicitly state when to use this tool versus alternatives like 'create_or_update_job_from_jenkinsfile' or 'stop_build'. It provides clear context for build initiation but lacks explicit exclusions or comparisons to sibling tools.

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/xhuaustc/jenkins-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server