A Python API for accessing resources and configuring Hudson & Jenkins continuous-integration servers
Python Other
Pull request Compare This branch is 993 commits ahead of ramonvanalteren:master.
Latest commit 9e204c3 Mar 16, 2017 @lechat lechat committed on GitHub Merge pull request #514 from Akasurde/master
Update index.rst
Permalink
Failed to load latest commit information.
.github Added issue template Aug 16, 2016
doc Update index.rst Nov 15, 2016
examples Cleaned up examples and added example of running job via invoke Oct 2, 2016
jenkinsapi Merge pull request #528 from ripcurld0/env_var_build Mar 1, 2017
jenkinsapi_tests Merge pull request #528 from ripcurld0/env_var_build Mar 1, 2017
jenkinsapi_utils Migrate to six (#507) Nov 1, 2016
misc add make venv utility script and version bump Apr 18, 2015
requirements Close #522 Only use parameter actions to access parameters. (#524) Dec 6, 2016
.gitignore Added PYPI deploy from travis on new tags Jul 25, 2016
.travis.yml Migrate to six (#507) Nov 1, 2016
Makefile Migrate to six (#507) Nov 1, 2016
README.rst Fix 'get_build_by_params' method (#506) Sep 27, 2016
TODO Changes badge and cleaned up TODO Aug 21, 2016
build.properties whitespace change Jun 23, 2013
build.xml revert accidental removel of unittest2 from the setup.py script Jul 13, 2014
jenkins_build.sh ensure virtualenv installed and WORKSPACE defined Oct 4, 2013
license.txt Try to be consistent about what type is returned Oct 6, 2013
pylintrc Converted most of the tests to pytest (#508) Oct 20, 2016
release.sh ensure that tags are pushed at the end of every build Jul 30, 2014
setup.cfg Update setup.cfg to support universal wheels Jan 29, 2016
setup.py Close #522 Only use parameter actions to access parameters. (#524) Dec 6, 2016
tox.ini Close #522 Only use parameter actions to access parameters. (#524) Dec 6, 2016

README.rst

jenkinsapi

https://badge.fury.io/py/jenkinsapi.png https://travis-ci.org/pycontribs/jenkinsapi.png?branch=master Requirements Status

About this library

Jenkins is the market leading continuous integration system, originally created by Kohsuke Kawaguchi.

Jenkins (and It's predecessor Hudson) are useful projects for automating common development tasks (e.g. unit-testing, production batches) - but they are somewhat Java-centric. Thankfully the designers have provided an excellent and complete REST interface. This library wraps up that interface as more conventional python objects in order to make many Jenkins oriented tasks easier to automate.

This library allows you to automate most common Jenkins operations using Python.

  • Ability to add/remove/query Jenkins jobs
  • Ability to execute jobs and:
    • Query the results of a completed build
    • Block until jobs are complete or run jobs asyncronously
    • Get objects representing the latest builds of a job
  • Work with build artefacts:
    • Search for artefacts by simple criteria
    • Install artefacts to custom-specified directory structures
  • Ability to search for builds by source code revision
  • Ability to add/remove/query:
    • Slaves (Webstart and SSH slaves)
    • Views (including nested views using NestedViews Jenkins plugin)
    • Credentials (username/password and ssh key)
  • Username/password auth support for jenkins instances with auth turned on
  • Ability to script jenkins installation including plugins

Python versions

The project have been tested and working on Python 2.7, 3.3 and 3.4. It was tested previously on Python 2.6, so it may work on this version too.

Jenkins versions

Project tested on both stable (LTS) and latest Jenkins versions.

Known issues

  • Job deletion operations fail unless Cross-Site scripting protection is disabled.

For other issues, please refer to the support URL below.

Important Links

Support and bug-reports: https://github.com/pycontribs/jenkinsapi/issues?direction=desc&sort=comments&state=open

Project source code: github: https://github.com/pycontribs/jenkinsapi

Project documentation: https://jenkinsapi.readthedocs.org/en/latest/

Releases: http://pypi.python.org/pypi/jenkinsapi

Installation

Egg-files for this project are hosted on PyPi. Most Python users should be able to use pip or setuptools to automatically install this project.

Using Pip or Setuptools

Most users can do the following:

pip install jenkinsapi

Or:

easy_install jenkinsapi

Both of these techniques can be combined with virtualenv to create an application-specific installation.

Using your operating-system's package manager

Ubuntu users can now use apt to install this package:

apt-get install python-jenkinsapi

Beware that this technique will get a somewhat older version of Jenkinsapi.

Example

JenkinsAPI is intended to map the objects in Jenkins (e.g. Builds, Views, Jobs) into easily managed Python objects:

>>> import jenkinsapi
>>> from jenkinsapi.jenkins import Jenkins
>>> J = Jenkins('http://localhost:8080')
>>> J.version
1.542
>>> J.keys() # Jenkins objects appear to be dict-like, mapping keys (job-names) to
['foo', 'test_jenkinsapi']
>>> J['test_jenkinsapi']
<jenkinsapi.job.Job test_jenkinsapi>
>>> J['test_jenkinsapi'].get_last_good_build()
<jenkinsapi.build.Build test_jenkinsapi #77>
...

More examples available on Github: https://github.com/pycontribs/jenkinsapi/tree/master/examples

Testing

If you have installed the test dependencies on your system already, you can run the testsuite with the following command:

python setup.py test

Otherwise using a virtualenv is recommended. Setuptools will automatically fetch missing test dependencies:

virtualenv
source .venv/bin/active
(venv) python setup.py test

Development

  • Make sure that you have Java installed.
  • Create virtual environment for development
  • Install package in development mode
(venv) pip install -e .
(venv) pip install -r requirements/dev-requirements.txt
  • Make your changes, write tests and check your code
(venv) nosetests -v jenkinsapi_tests

Project Contributors

Please do not contact these contributors directly for support questions! Use the GitHub tracker instead.

License

The MIT License (MIT): Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.