Registry / devops / python-jenkins

python-jenkins

JSON →
library1.8.3pypypi✓ verified 27d ago

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.

pip install python-jenkins
INSTALL
IMPORT
SIG · PYTHON-JENKINS
P
python-jenkins
devopspythonv1.8.3
Install
3.3s avg
Import
413ms
Disk
24MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.8.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.426s · 23.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.3s · import 0.400s · 24MB
24MB installed
● package 24MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Jenkins
from jenkins import Jenkins
JenkinsException
from jenkins import JenkinsException
For proper error handling and connection issues.

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.

import jenkins import os # Configure Jenkins connection details using environment variables for security JENKINS_URL = os.environ.get('JENKINS_URL', 'http://localhost:8080') JENKINS_USER = os.environ.get('JENKINS_USER', 'admin') JENKINS_API_TOKEN = os.environ.get('JENKINS_API_TOKEN', 'your_jenkins_api_token') # Prefer API token over password try: # Initialize the Jenkins client server = jenkins.Jenkins(JENKINS_URL, username=JENKINS_USER, password=JENKINS_API_TOKEN) # Get basic information user_info = server.get_whoami() jenkins_version = server.get_version() print(f'Connected to Jenkins {jenkins_version} as {user_info["fullName"]}') # List jobs jobs = server.get_jobs() print(f'Found {len(jobs)} jobs. First 5 job names:') for job in jobs[:5]: print(f'- {job["name"]}') except jenkins.JenkinsException as e: print(f"Error connecting to or interacting with Jenkins: {e}") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
deprecatedPrefer Jenkins API tokens over user passwords for authentication.
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.
affects: >=1.7.0
gotchaSSL certificate verification can fail with self-signed or corporate certificates.
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.
affects: All versions
gotchaConnection and API errors are raised as `jenkins.JenkinsException`.
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'jenkins'
The 'python-jenkins' library is not installed or is not available in the current Python environment.
fix
Run `pip install python-jenkins` to install the library.
jenkins.JenkinsException: Error in request. HTTP response code: 401
Authentication failed; the provided Jenkins username or API token is incorrect, or the user lacks necessary permissions.
fix
Verify your Jenkins username and API token, ensure the token is correctly generated, and that the user has appropriate read/write access.
jenkins.JenkinsException: Job[<job_name>] does not exist
The specified Jenkins job name does not exist on the server or is misspelled.
fix
Double-check the job name on your Jenkins server and ensure it matches exactly, including case sensitivity.
jenkins.JenkinsException: No valid crumb was included in the request
Jenkins has CSRF protection enabled, and the client did not include a valid crumb in the request for actions that modify server state.
fix
Initialize the Jenkins object with `crumb=True` (e.g., `server = jenkins.Jenkins(jenkins_url, username=user, password=token, crumb=True)`).
Upgrade
Version history
1.8.3latest on PyPI · released Aug 3, 2025
Audit
Dependencies
requestsrequiredHTTP client for communicating with the Jenkins API.
sixrequiredPython 2/3 compatibility layer (less critical for modern Python versions).
Agent activity
17 hits · last 30 days
node
16
Resources
python-jenkins — pip install python-jenkins · libregistry