Jenkins with Python
Jenkins provides a full set of RESTful APIs for its functionalities: https://wiki.jenkins.io/display/JENKINS/Remote+access+API. There are also a number of Python wrappers that make interaction even easier. Let's take a look at the python-jenkins
package:
(venv) $ pip install python-jenkins
We can test out the package with the following interactive prompt shell:
>>> import jenkins
>>> server = jenkins.Jenkins('http://192.168.2.124:8080', username='<user>', password='<pass>')
>>> user = server.get_whoami()
>>> version = server.get_version()
>>> print('Hello %s from Jenkins %s' % (user['fullName'], version))
Hello Admin from Jenkins 2.121.2
We can work with the management of the server, such as plugins
:
>>> plugin = server.get_plugins_info()
>>> plugin
[{'active': True, 'backupVersion...