Over the last 12 months I have made use of a great Python library originally written by Ken Conley in automating the various testing activities that we undertake as part of Ubuntu Development using Jenkins.
Python Jenkins provides Python bindings to the Jenkins Remote API.
I’m pleased to announce that Python Jenkins 0.2 is available in Ubuntu Oneiric Ocelot and the project has now migrated to Launchpad for bug tracking, version control and release management.
The 0.2 release includes a number of bug fixes and new methods for managing Jenkins slave node configuration remotely – this is already being used in the juju charm for Jenkins to automatically create new slave node configuration when slave node units are added to a deployed juju environment (blog posting to follow….)
A quick overview…
It’s pretty easy to get started with python-jenkins on the latest Ubuntu development release – if you are running an earlier release of Ubuntu then you can use the PPA (Natty only ATM but more to follow):
sudo apt-get install python-jenkins
The library is also published to PyPI so you can use pip if you are not running Ubuntu.
Here’s a quick example script:
#!/usr/bin/python import jenkins # Connect to instance - username and password are optional j = jenkins.Jenkins('http://hostname:8080', 'username', 'password') # Create a new job if not j.job_exists('empty'): j.create_job('empty', jenkins.EMPTY_CONFIG_XML) j.disable_job('empty') # Copy a job if j.job_exists('empty-copy'): j.delete_job('empty-copy') j.copy_job('empty', 'empty_copy') j.enable_job('empty_copy') # Reconfigure an existing job and build it j.reconfig_job('empty_copy', jenkins.RECONFIG_XML) j.build_job('empty_copy') # Create a slave node if j.node_exists('test-node'): j.delete_node('test-node') j.create_node('test-node')
You can find the current documentation here.
Happy automating!
