{"id":1680,"library":"python-jenkins","title":"Python Jenkins API Client","description":"Python-jenkins is a Python client library for the Jenkins Remote API, allowing programmatic interaction with Jenkins CI/CD servers. It provides methods to manage jobs, builds, nodes, plugins, and users. The current version is 1.8.3, and it receives maintenance releases roughly annually.","status":"active","version":"1.8.3","language":"python","source_language":"en","source_url":"https://github.com/exhuma/python-jenkins","tags":["jenkins","ci/cd","api client","automation"],"install":[{"cmd":"pip install python-jenkins","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"HTTP client for communicating with the Jenkins API.","package":"requests","optional":false},{"reason":"Python 2/3 compatibility layer (less critical for modern Python versions).","package":"six","optional":false}],"imports":[{"symbol":"Jenkins","correct":"from jenkins import Jenkins"},{"note":"For proper error handling and connection issues.","symbol":"JenkinsException","correct":"from jenkins import JenkinsException"}],"quickstart":{"code":"import jenkins\nimport os\n\n# Configure Jenkins connection details using environment variables for security\nJENKINS_URL = os.environ.get('JENKINS_URL', 'http://localhost:8080')\nJENKINS_USER = os.environ.get('JENKINS_USER', 'admin')\nJENKINS_API_TOKEN = os.environ.get('JENKINS_API_TOKEN', 'your_jenkins_api_token') # Prefer API token over password\n\ntry:\n    # Initialize the Jenkins client\n    server = jenkins.Jenkins(JENKINS_URL, username=JENKINS_USER, password=JENKINS_API_TOKEN)\n\n    # Get basic information\n    user_info = server.get_whoami()\n    jenkins_version = server.get_version()\n    print(f'Connected to Jenkins {jenkins_version} as {user_info[\"fullName\"]}')\n\n    # List jobs\n    jobs = server.get_jobs()\n    print(f'Found {len(jobs)} jobs. First 5 job names:')\n    for job in jobs[:5]:\n        print(f'- {job[\"name\"]}')\n\nexcept jenkins.JenkinsException as e:\n    print(f\"Error connecting to or interacting with Jenkins: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to connect to a Jenkins instance using environment variables for credentials (preferring API tokens), retrieve the current user and Jenkins version, and list existing jobs. It includes basic error handling for connection and API issues."},"warnings":[{"fix":"Generate an API token for your Jenkins user (User -> Configure -> Add new Token) and use it as the `password` argument in `jenkins.Jenkins()`. This enhances security.","message":"Prefer Jenkins API tokens over user passwords for authentication.","severity":"deprecated","affected_versions":">=1.7.0"},{"fix":"If you encounter SSL errors, you can disable SSL verification (use with caution in production) by passing `ssl_verify=False` to the `jenkins.Jenkins()` constructor. Alternatively, configure your system or the `requests` library to trust your certificate authority.","message":"SSL certificate verification can fail with self-signed or corporate certificates.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always wrap your Jenkins API calls in `try...except jenkins.JenkinsException:` blocks to gracefully handle network issues, authentication failures, and API-specific errors reported by the Jenkins server.","message":"Connection and API errors are raised as `jenkins.JenkinsException`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1.8.3':40 'allow':18 'annual':47 'api':3,17,50 'autom':52 'build':31 'ci/cd':23,49 'client':4,11,51 'current':37 'interact':20 'jenkin':2,7,15,22,48 'job':30 'librari':12 'mainten':44 'manag':29 'method':27 'node':32 'plugin':33 'programmat':19 'provid':26 'python':1,6,10 'python-jenkin':5 'receiv':43 'releas':45 'remot':16 'rough':46 'server':24 'user':35 'version':38","created_at":"2026-04-09T03:58:31.715043+00:00","updated_at":"2026-04-16T20:22:19.869368+00:00","problems":[{"fix":"Run `pip install python-jenkins` to install the library.","cause":"The 'python-jenkins' library is not installed or is not available in the current Python environment.","error":"ModuleNotFoundError: No module named 'jenkins'"},{"fix":"Verify your Jenkins username and API token, ensure the token is correctly generated, and that the user has appropriate read/write access.","cause":"Authentication failed; the provided Jenkins username or API token is incorrect, or the user lacks necessary permissions.","error":"jenkins.JenkinsException: Error in request. HTTP response code: 401"},{"fix":"Double-check the job name on your Jenkins server and ensure it matches exactly, including case sensitivity.","cause":"The specified Jenkins job name does not exist on the server or is misspelled.","error":"jenkins.JenkinsException: Job[<job_name>] does not exist"},{"fix":"Initialize the Jenkins object with `crumb=True` (e.g., `server = jenkins.Jenkins(jenkins_url, username=user, password=token, crumb=True)`).","cause":"Jenkins has CSRF protection enabled, and the client did not include a valid crumb in the request for actions that modify server state.","error":"jenkins.JenkinsException: No valid crumb was included in the request"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.8.3","cli_name":"","cli_version":null,"type":"library","homepage":"https://opendev.org/jjb/python-jenkins","github":null,"docs":"https://python-jenkins.readthedocs.io/","changelog":null,"pypi":"https://pypi.org/project/python-jenkins/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":null}}