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.

base_server_url()[source]
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

cancel_quiet_down()[source]

Cancel the effect of the quiet-down command

copy_job(jobname: str, newjobname: str) Job[source]
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

delete_view_by_url(viewurl: str)[source]
generate_new_api_token(new_token_name: str = 'Token By jenkinsapi python')[source]
get_artifact_data(id_)[source]
get_create_url() str[source]
get_credentials(cred_class=<class 'jenkinsapi.credentials.Credentials2x'>)[source]

Return credentials

get_executors(nodename: str) Executors[source]
get_jenkins_obj()[source]
get_jenkins_obj_from_url(url: str)[source]
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

get_jobs()[source]

Fetch all the build-names on this Jenkins server.

get_jobs_info()[source]

Get the jobs information :return url, name

get_jobs_list()[source]
get_label(label_name: str) Label[source]
get_master_data()[source]
get_node(nodename: str) Node[source]

Get a node object for a specific node

get_node_url(nodename: str = '') str[source]

Return the url for nodes

get_nodes() Nodes[source]
get_nodes_url() str[source]
get_plugins(depth: int = 1) Plugins[source]
get_plugins_url(depth)[source]
get_queue() Queue[source]
get_queue_url()[source]
get_view_by_url(view_url: str)[source]
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

has_plugin(plugin_name: str) bool[source]
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
items()[source]
Parameters:

return – A list of pairs. Each pair will be (job name, Job object)

iteritems()[source]
iterkeys()[source]
property jobs
keys()[source]
property nodes
property plugins
quiet_down()[source]

Put Jenkins in a Quiet mode, preparation for restart. No new builds started

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

safe_restart(wait_for_reboot: bool = True)[source]

restarts jenkins when no jobs are running

shutdown() None[source]
validate_fingerprint(id_)[source]
validate_fingerprint_for_build(digest, filename, job, build)[source]
property version: str

Return version number of Jenkins

property views