jenkinsflow.jenkins_api module

class jenkinsflow.jenkins_api.Jenkins(direct_uri, job_prefix_filter=None, username=None, password=None, invocation_class=None, rest_access_provider=<class 'jenkinsflow.rest_api_wrapper.RequestsRestApi'>)

Optimized minimal set of methods needed for jenkinsflow to access Jenkins jobs.

Parameters:
  • direct_uri (str) – Should be a non-proxied uri if possible (e.g. http://localhost:<port> if flow job is running on master) The public URI will be retrieved from Jenkins and used in output.
  • job_prefix_filter (str) – Jobs with names that don’t start with this string, will be skpped when polling Jenkins. If you are using Hudson and have many jobs, it might be a good idea to enable Team support and create a job-runner user, which only has access to the jobs in the flow that it is executing. That way the job list will be filtered serverside.
  • username (str) – Name of user authorized to execute all jobs in flow.
  • password (str) – Password of user.
  • invocation_class (class) – Defaults to Invocation.
set_build_description(description, replace=False, separator='\n', job_name=None, build_number=None)

Utility to set/append build description

Parameters:
  • description (str) – The description to set on the build
  • replace (bool) – If True, replace existing description, if any, instead of appending to it
  • separator (str) – A separator to insert between any existing description and the new description if replace is False.
  • job_name (str) – Name of the Jenkins job
  • build_number (int) – The build number for which to set the description
set_build_result(result, java='java', cli_call=False, protocol=<CliProtocol.remoting: 2>)

Change the result of a Jenkins job.

DEPRECATED - You should use the shell step exit code to determine the job result.

Note: set_build_result can only be done from within the job, not after the job has finished. Note: Only available if URL is set in Jenkins system configuration.

This command uses the Jenkins cli to change the result. It requires a java executable to run the cli. Note: In some versions of Jenkins the cli is broken, it has no manifest file! This is the case for e.g. 1.625.1, the version installed on Fedora 23 using dnf at the time of Fedora 23 release.

Parameters:
  • result (str) – The result to set. Should probably be ‘unstable’
  • java (str) – Alternative java executable. Use this if you don’t wish to use the java in the PATH.
  • protocol (CliProtocol) – Defaults to ‘remoting’ for backwards compatibility. See: https://jenkins.io/doc/book/managing/cli/.