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-jenkinsVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
Run `pip install python-jenkins` to install the library.
Verify your Jenkins username and API token, ensure the token is correctly generated, and that the user has appropriate read/write access.
Double-check the job name on your Jenkins server and ensure it matches exactly, including case sensitivity.
Initialize the Jenkins object with `crumb=True` (e.g., `server = jenkins.Jenkins(jenkins_url, username=user, password=token, crumb=True)`).