pyjen.utils.jenkins_api module
Base class for all objects that interact with the Jenkins REST API
- class pyjen.utils.jenkins_api.JenkinsAPI(url, session)[source]
Bases:
object
Abstraction around the raw Jenkins REST API
- Parameters
url (str) – URL of the Jenkins API endpoint to manage
session (requests.Session) – HTTP session to use for interacting with the Jenkins REST API
- clone(api_url)[source]
Creates a copy of this instance, for a new endpoint URL
- Parameters
api_url (str) – URL for the new REST API endpoint to be managed
- Returns
reference to the newly created API interface
- Return type
- property crumb
unique “crumb” identifier required by all POST operations
Introduced in Jenkins v2
Output from this helper can be used directly in post operations as an HTTP header, something like this:
requests.post(... headers=self.crumb)
reference: https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API (see CSRF protection section)
- Type
- get_api_data(target_url=None, query_params=None)[source]
retrieves the Jenkins API specific data from the specified URL
- Parameters
- Returns
The set of Jenkins attributes, converted to Python objects, associated with the given URL.
- Return type
- get_api_xml(path=None, params=None)[source]
Gets api XML data from a given REST API endpoint
- Parameters
- Returns
parsed XML data
- Return type
- property jenkins_headers
HTTP headers from the main Jenkins dashboard using the REST API
The dashboard headers contain metadata describing the Jenkins instance hosting the REST API, including details such as version number, current UI theme, and others.
- Type
- property jenkins_version
version number of the Jenkins server hosting this REST API, parsed into a tuple of integers
Typically returns a 3 tuple with the major, minor and update digits of the version number
- Type
- post(target_url, args=None)[source]
sends data to or triggers an operation via a Jenkins URL
- Parameters
- Returns
reference to the response data returned by the post request
- Return type
- property root_url
URL of the main Jenkins dashboard associated with the current object
NOTE: The URL returned by this property is guaranteed to end with a trailing slash character
- Type