Python Jenkins¶
README¶
Python Jenkins is a python wrapper for the Jenkins REST API which aims to provide a more conventionally pythonic way of controlling a Jenkins server. It provides a higher-level API containing a number of convenience functions.
We like to use python-jenkins to automate our Jenkins servers. Here are some of the things you can use it for:
Create new jobs
Copy existing jobs
Delete jobs
Update jobs
Get a job’s build information
Get Jenkins master version information
Get Jenkins plugin information
Start a build on a job
Create nodes
Enable/Disable nodes
Get information on nodes
Create/delete/reconfig views
Put server in shutdown mode (quiet down)
List running builds
Delete builds
Wipeout job workspace
Create/delete/update folders [1]
Set the next build number [2]
Install plugins
and many more..
To install:
$ sudo python setup.py install
Online documentation:
Developers¶
Bug report:
Repository:
Cloning:
git clone https://opendev.org/jjb/python-jenkins
Patches are submitted via Gerrit at:
Please do not submit GitHub pull requests, they will be automatically closed.
The python-jenkins developers communicate in the #openstack-jjb channel
on Freenode’s IRC network.
More details on how you can contribute is available on our wiki at:
Writing a patch¶
Be sure that you lint code before created an code review. The easiest way to do this is to install git pre-commit hooks.
Installing without setup.py¶
Then install the required python packages using pip:
$ sudo pip install python-jenkins
Footnotes
Contents¶
- API reference
JenkinsExceptionNotFoundExceptionEmptyResponseExceptionBadHTTPExceptionTimeoutExceptionWrappedSessionJenkinsJenkins.maybe_add_crumb()Jenkins.get_job_info()Jenkins.get_job_info_regex()Jenkins.get_job_name()Jenkins.debug_job_info()Jenkins.jenkins_open()Jenkins.jenkins_open_stream()Jenkins.jenkins_request()Jenkins.get_queue_item()Jenkins.get_build_info()Jenkins.get_build_env_vars()Jenkins.get_build_test_report()Jenkins.get_build_artifact()Jenkins.get_build_artifact_as_bytes()Jenkins.get_build_stages()Jenkins.get_queue_info()Jenkins.cancel_queue()Jenkins.get_info()Jenkins.get_whoami()Jenkins.get_version()Jenkins.get_plugins_info()Jenkins.get_plugin_info()Jenkins.get_plugins()Jenkins.get_jobs()Jenkins.get_all_jobs()Jenkins.copy_job()Jenkins.rename_job()Jenkins.delete_job()Jenkins.enable_job()Jenkins.disable_job()Jenkins.set_next_build_number()Jenkins.job_exists()Jenkins.jobs_count()Jenkins.assert_job_exists()Jenkins.create_folder()Jenkins.upsert_job()Jenkins.check_jenkinsfile_syntax()Jenkins.create_job()Jenkins.get_job_config()Jenkins.reconfig_job()Jenkins.build_job_url()Jenkins.build_job()Jenkins.run_script()Jenkins.install_plugin()Jenkins.stop_build()Jenkins.delete_build()Jenkins.wipeout_job_workspace()Jenkins.get_running_builds()Jenkins.get_nodes()Jenkins.get_node_info()Jenkins.node_exists()Jenkins.assert_node_exists()Jenkins.delete_node()Jenkins.disable_node()Jenkins.enable_node()Jenkins.create_node()Jenkins.get_node_config()Jenkins.reconfig_node()Jenkins.get_build_console_output()Jenkins.get_view_name()Jenkins.assert_view_exists()Jenkins.view_exists()Jenkins.get_views()Jenkins.delete_view()Jenkins.create_view()Jenkins.reconfig_view()Jenkins.get_view_config()Jenkins.get_promotion_name()Jenkins.assert_promotion_exists()Jenkins.promotion_exists()Jenkins.get_promotions_info()Jenkins.get_promotions()Jenkins.delete_promotion()Jenkins.create_promotion()Jenkins.reconfig_promotion()Jenkins.get_promotion_config()Jenkins.assert_folder()Jenkins.is_folder()Jenkins.assert_credential_exists()Jenkins.credential_exists()Jenkins.get_credential_info()Jenkins.get_credential_config()Jenkins.create_credential()Jenkins.delete_credential()Jenkins.reconfig_credential()Jenkins.list_credentials()Jenkins.quiet_down()Jenkins.wait_for_normal_op()
- Using Python-Jenkins
- Example 1: Get version of Jenkins
- Example 2: Logging into Jenkins using kerberos
- Example 3: Working with Jenkins Jobs
- Example 4: Working with Jenkins Views
- Example 5: Working with Jenkins Plugins
- Example 6: Working with Jenkins Nodes
- Example 7: Working with Jenkins Build Queue
- Example 8: Working with Jenkins Cloudbees Folders
- Example 9: Updating Next Build Number
- Example 9: Working with Build Promotions
- Example 10: Waiting for Jenkins to be ready
- Installing