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
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
- 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_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_downstream_job_names()[source]¶
Get all the possible downstream job names :return List of String
- 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_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_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_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
- 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]¶
- 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
- 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.