{"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":"en","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,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}