Jenkins¶
Module for jenkinsapi Jenkins object
- class jenkinsapi.jenkins.Jenkins(baseurl: str, username: str = '', password: str = '', requester=None, lazy: bool = False, ssl_verify: bool = True, cert=None, timeout: int = 10, use_crumb: bool = True, max_retries=None)[source]¶
Bases:
JenkinsBase
Represents a jenkins environment.
- build_job(jobname: str, params=None) None [source]¶
Invoke a build by job name :param jobname: name of exist job, str :param params: the job params, dict :return: none
- create_job(jobname: str, xml) Job [source]¶
Create a job
alternatively you can create job using Jobs object: self.jobs[‘job_name’] = config :param jobname: name of new job, str :param config: configuration of new job, xml :return: new Job obj
- create_multibranch_pipeline_job(jobname, xml, block=True, delay=60)[source]¶
- Returns:
list of new Job objects
- create_node(name: str, num_executors: int = 2, node_description: str = '', remote_fs: str = '/var/lib/jenkins', labels=None, exclusive: bool = False) Node [source]¶
Create a new JNLP slave node by name.
To create SSH node, please see description in Node class
- Parameters:
name – fqdn of slave, str
num_executors – number of executors, int
node_description – a freetext field describing the node
remote_fs – jenkins path, str
labels – labels to associate with slave, str
exclusive – tied to specific job, boolean
- Returns:
node obj
- create_node_with_config(name: str, config) Node | None [source]¶
Create a new slave node with specific configuration. Config should be resemble the output of node.get_node_attributes() :param str name: name of slave :param dict config: Node attributes for Jenkins API request
to create node (See function output Node.get_node_attributes())
- Returns:
node obj
- property credentials¶
- property credentials_by_id¶
- delete_job(jobname: str) None [source]¶
Delete a job by name :param jobname: name of a exist job, str :return: new jenkins_obj
- delete_node(nodename: str) None [source]¶
Remove a node from the managed slave list Please note that you cannot remove the master node
- Parameters:
nodename – string holding a hostname
- Returns:
None
- delete_plugin(plugin: str | Plugin, restart: bool = True, force_restart: bool = False, wait_for_reboot: bool = True, no_reboot_warning: bool = False) None [source]¶
Delete a plugin and optionally restart jenkins. Will not delete dependencies. @param plugin: Plugin (string or Plugin object) to be deleted @param restart: Boolean, restart Jenkins when required by plugin @param force_restart: Boolean, force Jenkins to restart,
ignoring plugin preferences
- delete_plugins(plugin_list, restart: bool = True, force_restart: bool = False, wait_for_reboot: bool = True, no_reboot_warning: bool = False)[source]¶
Delete a list of plugins and optionally restart jenkins. Will not delete dependencies. @param plugin_list: List of plugins (strings, Plugin objects or
a mix of the two) to be deleted
@param restart: Boolean, restart Jenkins when required by plugin @param force_restart: Boolean, force Jenkins to restart,
ignoring plugin preferences
- get_credentials(cred_class=<class 'jenkinsapi.credentials.Credentials2x'>)[source]¶
Return credentials
- get_job(jobname: str) Job [source]¶
Get a job by name :param jobname: name of the job, str :return: Job obj
- get_job_by_url(url: str, job_name: str) Job [source]¶
Get a job by url :param url: jobs’ url :param jobname: name of the job, str :return: Job obj
- has_job(jobname: str) bool [source]¶
Does a job by the name specified exist :param jobname: string :return: boolean
- has_node(nodename: str) bool [source]¶
Does a node by the name specified exist :param nodename: string, hostname :return: boolean
- install_plugin(plugin: str | Plugin, restart: bool = True, force_restart: bool = False, wait_for_reboot: bool = True, no_reboot_warning: bool = False)[source]¶
Install a plugin and optionally restart jenkins. @param plugin: Plugin (string or Plugin object) to be installed @param restart: Boolean, restart Jenkins when required by plugin @param force_restart: Boolean, force Jenkins to restart,
ignoring plugin preferences
@param no_warning: Don’t show warning when restart is needed and restart parameters are set to False
- install_plugins(plugin_list, restart: bool = True, force_restart: bool = False, wait_for_reboot: bool = True, no_reboot_warning: bool = False) None [source]¶
Install a list of plugins and optionally restart jenkins. @param plugin_list: List of plugins (strings, Plugin objects or
a mix of the two) to be installed
@param restart: Boolean, restart Jenkins when required by plugin @param force_restart: Boolean, force Jenkins to restart,
ignoring plugin preferences
- property is_quieting_down: bool¶
- property jobs¶
- property nodes¶
- property plugins¶
- rename_job(jobname: str, newjobname: str) Job [source]¶
Rename a job :param jobname: name of a exist job, str :param newjobname: name of new job, str :return: new Job obj
- run_groovy_script(script: str) str [source]¶
Runs the requested groovy script on the Jenkins server returning the result as text. Raises a JenkinsAPIException if the returned HTTP response code from the POST request is not 200 OK.
Example:
server = Jenkins(…) script = ‘println “Hello world!”’ result = server.run_groovy_script(script) print(result) # will print “Hello world!”
- safe_exit(wait_for_exit: bool = True, max_wait: int = 360)[source]¶
Restarts jenkins when no jobs are running, except for pipeline jobs
- property version: str¶
Return version number of Jenkins
- property views¶