pyjen.utils.jenkins_api module¶
Base class for all objects that interact with the Jenkins REST API
-
class
pyjen.utils.jenkins_api.
JenkinsAPI
(url, creds, ssl_cert)[source]¶ Bases:
object
Abstraction around the raw Jenkins REST API
- Parameters
.
-
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
newly created JenkinsAPI
- Return type
-
crumb
¶ Gets a 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)
- Return 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
-
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.
- Return type
-
jenkins_version
¶ Gets the version number of the Jenkins server hosting this REST API
Typically returns a 3 tuple with the major, minor and update digits of the version number
- Return type
-
post
(target_url, args=None)[source]¶ sends data to or triggers an operation via a Jenkins URL
- Parameters
target_url (str) – Full URL to sent post request to
args (dict) –
optional set of data arguments to be sent with the post operation. Supported keys are as follows:
- ’headers’ - dictionary of HTTP header properties and their
associated values
- ’data’ - dictionary of assorted / misc data properties and
their values
- ’files’ - dictionary of file names and handles to be uploaded to
the target URL
’params’ - form data to be passed to the API endpoint
- Returns
reference to the response data returned by the post request
- Return type
requests.models.Response
-
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
- Return type