Skip to main content
Glama
xhuaustc

Jenkins MCP Tool

create_or_update_job_from_jenkinsfile

Create or update Jenkins CI/CD jobs using Jenkinsfile pipeline definitions to automate deployment and testing workflows.

Instructions

Create or update a Jenkins job based on a Jenkinsfile.

Args:
    server_name: Jenkins server name
    job_name: Name for the job (create if not exists, update if exists)
    jenkinsfile_content: Content of the Jenkinsfile (pipeline script)
    description: Optional job description
    ctx: MCP context (for logging)

Returns:
    Dict containing job creation/update result with status and job_url

Raises:
    JenkinsError: Job creation/update failed

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
server_nameYes
job_nameYes
jenkinsfile_contentYes
descriptionNo

Implementation Reference

  • The handler function for the 'create_or_update_job_from_jenkinsfile' tool. It is decorated with @mcp.tool() for registration and implements the logic to create or update a Jenkins pipeline job using the provided Jenkinsfile content, organizing jobs under a user-specific folder.
    @mcp.tool()
    def create_or_update_job_from_jenkinsfile(
        server_name: str,
        job_name: str,
        jenkinsfile_content: str,
        description: str = "",
        ctx: Context = None,
    ) -> dict:
        """Create or update a Jenkins job based on a Jenkinsfile.
    
        Args:
            server_name: Jenkins server name
            job_name: Name for the job (create if not exists, update if exists)
            jenkinsfile_content: Content of the Jenkinsfile (pipeline script)
            description: Optional job description
            ctx: MCP context (for logging)
    
        Returns:
            Dict containing job creation/update result with status and job_url
    
        Raises:
            JenkinsError: Job creation/update failed
        """
        client = JenkinsAPIClient(server_name)
    
        # Organize all jobs under MCPS/username directory
        # Get username from Jenkins server config, extract part before @ if it's an email
        server_config = client._server_config
        username = server_config.get("user", "unknown")
        if "@" in username:
            username = username.split("@")[0]
    
        final_folder_path = f"MCPS/{username}"
        job_full_name = f"{final_folder_path}/{job_name}"
    
        # Create job configuration XML for pipeline job
        job_config = f"""<?xml version='1.1' encoding='UTF-8'?>
    <flow-definition plugin="workflow-job">
      <actions/>
      <description>{description}</description>
      <keepDependencies>false</keepDependencies>
      <properties/>
      <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps">
        <script>{jenkinsfile_content}</script>
        <sandbox>true</sandbox>
      </definition>
      <triggers/>
      <disabled>false</disabled>
    </flow-definition>"""
    
        # Check if job already exists
        try:
            print(f"===job_full_name: {job_full_name}", flush=True)
            existing_job = client.get_job_info(job_full_name)
            print(f"=====existing_job: {existing_job}", flush=True)
            # Job exists, update it
            if ctx:
                ctx.log("info", f"Updating existing job '{job_name}' on {server_name}")
                ctx.log("debug", f"Target folder: {final_folder_path}")
    
            return client.update_job(job_name, job_config, final_folder_path)
        except Exception as e:
            # Job doesn't exist, create it
            print(e, flush=True)
            if ctx:
                ctx.log("info", f"Creating new job '{job_name}' on {server_name}")
                ctx.log("debug", f"Target folder: {final_folder_path}")
    
            return client.create_job(job_name, job_config, final_folder_path)
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the core action (create/update job) and mentions error handling ('Raises: JenkinsError'), but lacks details on permissions, side effects, rate limits, or what happens to existing job configurations. It adds some context but is incomplete for a mutation tool.

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

Conciseness4/5

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

The description is well-structured with clear sections (Args, Returns, Raises) and front-loaded purpose. It is appropriately sized, but the inclusion of 'ctx' in Args, which is typically implicit in MCP, adds minor verbosity without significant value. Most sentences earn their place efficiently.

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

Completeness3/5

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

Given the complexity of a mutation tool with no annotations and no output schema, the description is moderately complete. It covers parameters and basic behavior but lacks details on return values beyond a generic 'Dict', error specifics, or operational constraints. It meets minimum viability but has clear gaps for full agent understanding.

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

Parameters5/5

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

The description provides detailed semantics for all parameters beyond the input schema, which has 0% description coverage. It explains what each parameter represents (e.g., 'Jenkins server name', 'Content of the Jenkinsfile'), clarifies optionality for 'description', and notes the purpose of 'ctx'. This fully compensates for the schema's lack of descriptions.

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 specific action ('Create or update a Jenkins job') and the resource ('based on a Jenkinsfile'), distinguishing it from sibling tools like get_build_log or trigger_build which perform different operations. It precisely defines the verb and target without ambiguity.

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

Usage Guidelines3/5

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

The description implies usage through the phrase 'create if not exists, update if exists', suggesting when to use it, but does not explicitly state when to choose this tool over alternatives like search_jobs or validate_jenkins_config. No exclusions or prerequisites are mentioned, leaving some guidance gaps.

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