search_jobs
Search Jenkins jobs on a specified server using a keyword. Streamline job discovery by retrieving a list of matching jobs, aiding in efficient CI/CD operations.
Instructions
Search Jenkins jobs on the specified server.
Note: For deployment tasks, it is recommended to use get_scenario_list() and search_jobs_by_scenario().
Args:
server_name: Jenkins server name
keyword: Search keyword
Returns:
List of matching jobs
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keyword | Yes | ||
| server_name | Yes |
Implementation Reference
- src/jenkins/tools/mcp_tools.py:72-86 (handler)The primary handler for the MCP tool 'search_jobs'. This function is decorated with @mcp.tool(), defining its schema via type hints and docstring, and registers it. It creates a JenkinsAPIClient instance and calls its search_jobs method to perform the search.@mcp.tool() def search_jobs(server_name: str, keyword: str) -> List[JobInfo]: """Search Jenkins jobs on the specified server. Note: For deployment tasks, it is recommended to use get_scenario_list() and search_jobs_by_scenario(). Args: server_name: Jenkins server name keyword: Search keyword Returns: List of matching jobs """ client = JenkinsAPIClient(server_name) return client.search_jobs(keyword)
- src/jenkins/tools/client.py:501-535 (helper)The core helper function implementing the job search logic in JenkinsAPIClient. It recursively collects all jobs from the Jenkins API root, filters by keyword matching name or fullName, and enriches matches with full job info.def search_jobs(self, keyword: str) -> List[JobInfo]: """Search jobs. Args: keyword: Search keyword Returns: List of matching jobs Raises: JenkinsError: API request failed """ api_url = ( f"{self._client.base_url}/api/json?tree=jobs[name,url,fullName," "jobs[name,url,fullName,jobs[name,url,fullName,jobs[name,url,fullName]]]]" ) response = self._make_request("GET", api_url) response.raise_for_status() data = response.json() all_jobs = self._collect_all_jobs(data.get("jobs", [])) # Filter matching jobs matching_jobs = [] for job in all_jobs: if ( keyword.lower() in job["name"].lower() or keyword.lower() in job.get("fullName", "").lower() ): job_info = self.get_job_info(job["fullName"]) matching_jobs.append(job_info) return matching_jobs