Jobs and job

Jobs

This module implements the Jobs class, which is intended to be a container-like interface for all of the jobs defined on a single Jenkins server.

class jenkinsapi.jobs.Jobs(jenkins: Jenkins)[source]

Bases: object

This class provides a container-like API which gives access to all jobs defined on the Jenkins server. It behaves like a dict in which keys are Job-names and values are actual jenkinsapi.Job objects.

build(job_name: str, params=None, **kwargs) QueueItem[source]

Executes build of a job

Parameters:
  • job_name (str) – Job name

  • params (dict) – Job parameters

  • kwargs – Parameters for Job.invoke() function

Returns QueueItem:

Object to track build progress

copy(job_name: str, new_job_name: str) Job[source]

Copy a job :param str job_name: Name of an existing job :param new_job_name: Name of new job :returns Job: new Job object

create(job_name: str, config: str | bytes) Job[source]

Create a job

Parameters:
  • jobname (str) – Name of new job

  • config (str) – XML configuration of new job

Returns Job:

new Job object

create_multibranch_pipeline(job_name: str, config: str, block: bool = True, delay: int = 60) list[Job][source]

Create a multibranch pipeline job

Parameters:
  • jobname (str) – Name of new job

  • config (str) – XML configuration of new job

  • block – block until scan is finished?

  • delay – max delay to wait for scan to finish (seconds)

:returns list of new Jobs after scan

iteritems() Iterator[str, 'Job'][source]

Iterate over the names & objects for all jobs

iterkeys() Iterator[str][source]

Iterate over the names of all available jobs

itervalues() Iterator[Job][source]

Iterate over all available jobs

keys() list[str][source]

Return a list of the names of all jobs

poll(tree='jobs[name,color,url]')[source]
rename(job_name: str, new_job_name: str) Job[source]

Rename a job

Parameters:
  • job_name (str) – Name of an existing job

  • new_job_name (str) – Name of new job

Returns Job:

new Job object

Job

Module for jenkinsapi Job

class jenkinsapi.job.Job(url: str, name: str, jenkins_obj: Jenkins)[source]

Bases: JenkinsBase, MutableJenkinsThing

Represents a jenkins job A job can hold N builds which are the actual execution environments

delete_build(build_number)[source]

Remove build

Parameters:

build_number (int) – Build number

Raises:

NotFound – When build is not found

delete_from_queue()[source]

Delete a job from the queue only if it’s enqueued :raise NotInQueue if the job is not in the queue

disable()[source]

Disable job

enable()[source]

Enable job

get_build(buildnumber)[source]
get_build_by_params(build_params, order=1)[source]
get_build_dict()[source]
get_build_ids()[source]

Return a sorted list of all good builds as ints.

get_build_metadata(buildnumber)[source]

Get the build metadata for a given build number. For large builds with tons of tests, this method is faster than get_build by returning less data.

get_build_triggerurl() str[source]
get_buildnumber_for_revision(revision, refresh=False)[source]
Parameters:
  • revision – subversion revision to look for, int

  • refresh – boolean, whether or not to refresh the revision -> buildnumber map

Returns:

list of buildnumbers, [int]

get_config()[source]

Returns the config.xml from the job

get_config_xml_url()[source]
get_description() str[source]
get_downstream_job_names()[source]

Get all the possible downstream job names :return List of String

get_downstream_jobs()[source]

Get all the possible downstream jobs :return List of Job

get_first_build()[source]
get_first_buildnumber()[source]

Get the numerical ID of the first build.

get_full_name()[source]

Get the full name for a job (including parent folders) from the job URL.

static get_full_name_from_url_and_baseurl(url, baseurl)[source]

Get the full name for a job (including parent folders) from the job URL.

get_jenkins_obj() Jenkins[source]
get_last_build()[source]

Get the last build

get_last_build_or_none()[source]

Get the last build or None if there is no builds

get_last_buildnumber()[source]

Get the numerical ID of the last build.

get_last_completed_build()[source]

Get the last build regardless of status

get_last_completed_buildnumber()[source]

Get the numerical ID of the last complete build.

get_last_failed_buildnumber()[source]

Get the numerical ID of the last failed build.

get_last_good_build()[source]

Get the last good build

get_last_good_buildnumber()[source]

Get the numerical ID of the last good build.

get_last_stable_build()[source]

Get the last stable build

get_last_stable_buildnumber()[source]

Get the numerical ID of the last stable build.

get_next_build_number()[source]

Return the next build number that Jenkins will assign.

get_params()[source]

Get the parameters for this job. Format varies by parameter type. Here is an example string parameter:

{

‘type’: ‘StringParameterDefinition’, ‘description’: ‘Parameter description’, ‘defaultParameterValue’: {‘value’: ‘default value’}, ‘name’: ‘FOO_BAR’

}

get_params_list()[source]

Gets the list of parameter names for this job.

get_queue_item()[source]

Return a QueueItem if this object is in a queue, otherwise raise an exception

get_revision_dict()[source]

Get dictionary of all revisions with a list of buildnumbers (int) that used that particular revision

get_scm_branch()[source]

Get list of SCM branches : return: list of SCM branches

get_scm_type()[source]
get_scm_url()[source]

Get list of project SCM urls For some SCM’s jenkins allow to configure and use number of SCM url’s : return: list of SCM urls

get_upstream_job_names()[source]

Get all the possible upstream job names :return List of String

get_upstream_jobs()[source]

Get all the possible upstream jobs :return List of Job

has_params()[source]

If job has parameters, returns True, else False

has_queued_build(build_params)[source]

Returns True if a build with build_params is currently queued.

invoke(securitytoken=None, block: bool = False, build_params=None, cause=None, files=None, delay: int = 5, quiet_period=None) QueueItem[source]
is_enabled()[source]
is_queued()[source]
is_queued_or_running()[source]
is_running()[source]
load_config()[source]
static mk_json_from_build_parameters(build_params, file_params=None)[source]
modify_scm_branch(new_branch, old_branch=None)[source]

Modify SCM (“Source Code Management”) branch name for configured job. :param new_branch : new repository branch name to set.

If job has multiple branches configured and “old_branch” not provided - method will allways modify first url.

Parameters:

(optional) (old_branch) – exact value of branch name to be replaced. For some SCM’s jenkins allow set multiple branches per job this parameter intended to indicate which branch need to be modified

modify_scm_url(new_source_url, old_source_url=None)[source]

Modify SCM (“Source Code Management”) url for configured job. :param new_source_url : new repository url to set.

If job has multiple repositories configured and “old_source_url” not provided - method will allways modify first url.

Parameters:

(optional) (old_source_url) – for some SCM’s jenkins allows settting multiple repositories per job this parameter intended to indicate which repository need to be modified

poll(tree=None)[source]
toggle_keep_build(build_number)[source]
update_config(config, full_response=False, encoding='utf-8')[source]

Update the config.xml to the job Also refresh the ElementTree object since the config has changed :param full_response (optional): if True, it will return the full

response object instead of just the response text. Useful for debugging and validation workflows.