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
url (str) – URL of the Jenkins REST API endpoint to manage
creds (tuple) – username and password pair to authenticate with when accessing the REST API
ssl_cert – Either a boolean controlling SSL verification, or a path to a cert authority bundle to use for SSL verification.
.
-
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
dict
-
get_api_data
(target_url=None, query_params=None)[source]¶ retrieves the Jenkins API specific data from the specified URL
- Parameters
target_url (str) – Full URL to the REST API endpoint to be queried. If not provided, data will be loaded from the default ‘url’ for this object
query_params (str) – optional set of query parameters to customize the returned data
- Returns
The set of Jenkins attributes, converted to Python objects, associated with the given URL.
- Return type
dict
-
get_api_xml
(path=None, params=None)[source]¶ Gets api XML data from a given REST API endpoint
- Parameters
path (str) – optional extension path to append to the root URL managed by this object when performing the get operation
params (dict) – optional query parameters to be passed to the request
- Returns
parsed XML data
-
get_text
(path=None, params=None)[source]¶ gets the raw text data from a Jenkins URL
- Parameters
path (str) – optional extension path to append to the root URL managed by this object when performing the get operation
params (dict) – optional query parameters to be passed to the request
- Returns
the text loaded from this objects’ URL
- Return type
str
-
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
dict
-
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
tuple
-
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
str
-
url
¶ Gets the URL for the REST API endpoint managed by this object
NOTE: The URL returned by this property is guaranteed to end with a trailing slash character
- Return type
str