API reference

class api4jenkins.Jenkins(url, **kwargs)[source]

Constructs Jenkins.

Parameters
  • url – URL of Jenkins server, str

  • auth – (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.

  • token – (optional) Boolean, Create user token when initialize instance and revoke token once instance is destroied. useful when LDAP server refuse username and password used too much often. Defaults to False.

  • **kwargs – other kwargs are same as requests.Session.request

Usage:

>>> from api4jenkins import Jenkins
>>> j = Jenkins('http://127.0.0.1:8080/', auth=('admin', 'admin'))
>>> print(j)
<Jenkins: http://127.0.0.1:8080/>
>>> j.version
'2.176.2'
api_json(tree='', depth=0)
api_xml()
property attrs
build_job(full_name, parameters=None)[source]

Build job with/without parameters

Parameters
  • full_namestr, full name of job

  • parameters – None or Dict, support delay and remote token

Returns

QueueItem

Usage:

>>> from api4jenkins import Jenkins
>>> j = Jenkins('http://127.0.0.1:8080/', auth=('admin', 'admin'))
>>> item = j.build_job('freestylejob')
>>> import time
>>> while not item.get_build():
...      time.sleep(1)
>>> build = item.get_build()
>>> print(build)
<FreeStyleBuild: http://127.0.0.1:8080/job/freestylejob/1/>
>>> for line in build.progressive_output():
...     print(line)
...
check_name(name)
class_delimiter = re.compile('[.$]')
copy_job(full_name, dest)[source]

Create job by copying other job, the source job and dest job are in same folder.

Parameters
  • full_name – full name of source job

  • dest – name of new job

Usage:

>>> from api4jenkins import Jenkins
>>> j = Jenkins('http://127.0.0.1:8080/', auth=('admin', 'admin'))
>>> j.copy_job('folder/freestylejob', 'newjob')
>>> j.get_job('folder/newjob')
>>> print(job)
<FreeStyleProject: http://127.0.0.1:8080/job/folder/job/newjob/>
create_job(full_name, xml)[source]

Create new jenkins job with given xml configuration

Parameters
  • full_namestr, full name of job

  • xml – xml configuration string

Usage:

>>> from api4jenkins import Jenkins
>>> j = Jenkins('http://127.0.0.1:8080/', auth=('admin', 'admin'))
>>> xml = """<?xml version='1.1' encoding='UTF-8'?>
... <project>
...   <builders>
...     <hudson.tasks.Shell>
...       <command>echo $JENKINS_VERSION</command>
...     </hudson.tasks.Shell>
...   </builders>
... </project>"""
>>> j.create_job('freestylejob', xml)
>>> job = j.get_job('freestylejob')
>>> print(job)
<FreeStyleProject: http://127.0.0.1:8080/job/freestylejob/>
property credentials

An object for managing credentials. see Credentials

property crumb

Crumb of Jenkins

delete_job(full_name)[source]

Delete job

Parameters

full_namestr, full name of job

Usage:

>>> from api4jenkins import Jenkins
>>> j = Jenkins('http://127.0.0.1:8080/', auth=('admin', 'admin'))
>>> job = j.get_job('freestylejob')
>>> print(job)
<FreeStyleProject: http://127.0.0.1:8080/job/freestylejob/>
>>> j.delete_job('freestylejob')
>>> job = j.get_job('freestylejob')
>>> print(job)
None
exists()[source]

Check if Jenkins server is up

Returns

Ture or False

get_job(full_name)[source]

Get job by full name

Parameters

full_namestr, full name of job

Returns

Corresponding Job object or None

Usage:

>>> from api4jenkins import Jenkins
>>> j = Jenkins('http://127.0.0.1:8080/', auth=('admin', 'admin'))
>>> job = j.get_job('freestylejob')
>>> print(job)
<FreeStyleProject: http://127.0.0.1:8080/job/freestylejob/>
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_jobs(depth=0)[source]

Iterate jobs with depth

Parameters

depthint, depth to iterate, default is 0

Returns

iterator of jobs

Usage:

>>> from api4jenkins import Jenkins
>>> j = Jenkins('http://127.0.0.1:8080/', auth=('admin', 'admin'))
>>> for job in j.iter_jobs():
...     print(job)
<FreeStyleProject: http://127.0.0.1:8080/job/freestylejob/>
...
property nodes

An object for managing nodes. see Nodes

property plugins

An object for managing plugins. see PluginsManager

property queue

An object for managing build queue. see Queue

property system

An object for managing system operation. see System

property version

Version of Jenkins

property views

An object for managing views of main window. see Views

class api4jenkins.job.BitbucketSCMNavigator(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
build(parameters=None)
property building
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable()
duplicate(path)
enable()
exists()
get_build(number)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
move(path)
property parent
rename(name)
set_description(text)
set_next_build_number(number)
class api4jenkins.job.ExternalJob(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
build(parameters=None)
property building
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable()
duplicate(path)
enable()
exists()
get_build(number)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
move(path)
property parent
rename(name)
set_description(text)
set_next_build_number(number)
class api4jenkins.job.Folder(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
copy(src, dest)[source]
create(name, xml)[source]
property credentials
delete()
duplicate(path)
exists()
get(name)[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter(depth=0)[source]
move(path)
property parent
reload()[source]
rename(name)
set_description(text)
property views
class api4jenkins.job.FreeStyleProject(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
build(parameters=None)
property building
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable()
duplicate(path)
enable()
exists()
get_build(number)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
move(path)
property parent
rename(name)
set_description(text)
set_next_build_number(number)
class api4jenkins.job.GitHubSCMNavigator(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
build(parameters=None)
property building
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable()
duplicate(path)
enable()
exists()
get_build(number)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
move(path)
property parent
rename(name)
set_description(text)
set_next_build_number(number)
class api4jenkins.job.IvyModuleSet(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
build(parameters=None)
property building
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable()
duplicate(path)
enable()
exists()
get_build(number)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
move(path)
property parent
rename(name)
set_description(text)
set_next_build_number(number)
class api4jenkins.job.Job(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
duplicate(path)[source]
exists()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
move(path)[source]
property parent
rename(name)[source]
set_description(text)
class api4jenkins.job.MatrixProject(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
build(parameters=None)
property building
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable()
duplicate(path)
enable()
exists()
get_build(number)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
move(path)
property parent
rename(name)
set_description(text)
set_next_build_number(number)
class api4jenkins.job.MavenModuleSet(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
build(parameters=None)
property building
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable()
duplicate(path)
enable()
exists()
get_build(number)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
move(path)
property parent
rename(name)
set_description(text)
set_next_build_number(number)
class api4jenkins.job.MultiJobProject(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
build(parameters=None)
property building
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable()
duplicate(path)
enable()
exists()
get_build(number)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
move(path)
property parent
rename(name)
set_description(text)
set_next_build_number(number)
class api4jenkins.job.Project(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
build(parameters=None)[source]
property building
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable()[source]
duplicate(path)
enable()[source]
exists()
get_build(number)[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()[source]
move(path)
property parent
rename(name)
set_description(text)
set_next_build_number(number)[source]
class api4jenkins.job.WorkflowJob(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
build(parameters=None)
property building
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable()
duplicate(path)
enable()
exists()
get_build(number)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
move(path)
property parent
rename(name)
set_description(text)
set_next_build_number(number)
class api4jenkins.job.WorkflowMultiBranchProject(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
copy(src, dest)
create(name, xml)
property credentials
delete()
duplicate(path)
exists()
get(name)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter(depth=0)
move(path)
property parent
reload()
rename(name)
set_description(text)
property views
class api4jenkins.build.Build(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
console_text(stream=False)[source]
delete()
exists()
get_job()[source]
get_next_build()[source]
get_previous_build()[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
kill()[source]
progressive_output(html=False)[source]
retrigger()[source]
set_description(text)
stop()[source]
term()[source]
class api4jenkins.build.FreeStyleBuild(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
console_text(stream=False)
delete()
exists()
get_job()
get_next_build()
get_previous_build()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
kill()
progressive_output(html=False)
retrigger()
set_description(text)
stop()
term()
class api4jenkins.build.MatrixBuild(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
console_text(stream=False)
delete()
exists()
get_job()
get_next_build()
get_previous_build()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
kill()
progressive_output(html=False)
retrigger()
set_description(text)
stop()
term()
class api4jenkins.build.WorkflowRun(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
console_text(stream=False)
delete()
exists()
get_job()
get_next_build()
get_previous_build()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
kill()
progressive_output(html=False)
retrigger()
set_description(text)
stop()
term()
class api4jenkins.queue.BlockedItem(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
cancel()
check_name(name)
class_delimiter = re.compile('[.$]')
exists()
get_build()
get_job()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
class api4jenkins.queue.BuildableItem(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
cancel()
check_name(name)
class_delimiter = re.compile('[.$]')
exists()
get_build()
get_job()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
class api4jenkins.queue.LeftItem(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
cancel()
check_name(name)
class_delimiter = re.compile('[.$]')
exists()
get_build()
get_job()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
class api4jenkins.queue.Queue(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
cancel(id)[source]
check_name(name)
class_delimiter = re.compile('[.$]')
exists()
get(id)[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
class api4jenkins.queue.QueueItem(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
cancel()[source]
check_name(name)
class_delimiter = re.compile('[.$]')
exists()
get_build()[source]
get_job()[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
class api4jenkins.queue.WaitingItem(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
cancel()
check_name(name)
class_delimiter = re.compile('[.$]')
exists()
get_build()
get_job()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
class api4jenkins.credential.Credential(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
exists()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
class api4jenkins.credential.Credentials(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
create(xml)[source]
exists()
get(name)[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
class api4jenkins.node.DockerComputer(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable(msg='')
enable()
exists()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
run_script(script)
class api4jenkins.node.KubernetesComputer(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable(msg='')
enable()
exists()[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
run_script(script)
class api4jenkins.node.MasterComputer(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable(msg='')
enable()
exists()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
run_script(script)
class api4jenkins.node.Node(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable(msg='')[source]
enable()[source]
exists()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()[source]
run_script(script)
class api4jenkins.node.Nodes(jenkins, url)[source]

classdocs

api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
create(name, **kwargs)[source]
exists()
get(name)[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()[source]
class api4jenkins.node.SlaveComputer(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
disable(msg='')
enable()
exists()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
iter_builds()
run_script(script)
class api4jenkins.plugin.Plugin(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
exists()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
uninstall()[source]
class api4jenkins.plugin.PluginsManager(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
check_updates_server()[source]
class_delimiter = re.compile('[.$]')
exists()
get(name)[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
install(*names, block=False)[source]
property installation_done
property restart_required
set_proxy(name, port, *, username='', password='', no_proxy='', test_url='')[source]
set_site(url)[source]
property site
uninstall(*names)[source]
property update_center
class api4jenkins.plugin.UpdateCenter(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
exists()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
property installation_done
property restart_required
property site
class api4jenkins.view.AllView(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
exclude(name)
exists()
get_job(name)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
include(name)
class api4jenkins.view.ListView(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
exclude(name)
exists()
get_job(name)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
include(name)
class api4jenkins.view.MyView(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
exclude(name)
exists()
get_job(name)
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
include(name)
class api4jenkins.view.View(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
configure(xml=None)
delete()
exclude(name)[source]
exists()
get_job(name)[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
include(name)[source]
class api4jenkins.view.Views(provider)[source]

classdocs

api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
create(name, xml)[source]
exists()
get(name)[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
class api4jenkins.system.System(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
cancel_quiet_down()[source]
check_name(name)
class_delimiter = re.compile('[.$]')
exists()
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
quiet_down()[source]
restart()[source]
run_script(script)
safe_restart()[source]
show_credential()[source]
class api4jenkins.user.ApiToken(name, uuid, value)[source]
count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

property name

Alias for field number 0

property uuid

Alias for field number 1

property value

Alias for field number 2

class api4jenkins.user.User(jenkins, url)[source]
api_json(tree='', depth=0)
api_xml()
property attrs
check_name(name)
class_delimiter = re.compile('[.$]')
exists()
generate_token(name='')[source]
handle_req(method, entry, **kwargs)
headers = {'Content-Type': 'text/xml; charset=utf-8'}
revoke_token(uuid)[source]
class api4jenkins.item.Item(jenkins, url)[source]

classdocs

api_json(tree='', depth=0)[source]
api_xml()[source]
property attrs
check_name(name)[source]
class_delimiter = re.compile('[.$]')
exists()[source]
handle_req(method, entry, **kwargs)[source]
headers = {'Content-Type': 'text/xml; charset=utf-8'}
api4jenkins.item.append_slash(url)[source]
api4jenkins.item.camel(s)[source]
api4jenkins.item.snake(s)[source]
class api4jenkins.mix.ConfigrationMix[source]
configure(xml=None)[source]
class api4jenkins.mix.DeletionMix[source]
delete()[source]
class api4jenkins.mix.DescriptionMix[source]
set_description(text)[source]
class api4jenkins.mix.RunScriptMix[source]
run_script(script)[source]
api4jenkins.requester.Requester(**kwargs)[source]
exception api4jenkins.exceptions.AuthenticationError[source]
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception api4jenkins.exceptions.BadRequestError[source]
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception api4jenkins.exceptions.ItemExistsError[source]
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception api4jenkins.exceptions.ItemNotFoundError[source]
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception api4jenkins.exceptions.ServerError[source]
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception api4jenkins.exceptions.UnsafeCharacterError[source]
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.