Jenkins with Python

Jenkins provides a full set of REST APIs for its functionalities: https://wiki.jenkins.io/display/JENKINS/Remote+access+API. There are also a number of Python wrappers that make the interaction even easier. Let's take a look at the Python-Jenkins package:

$ sudo pip3 install python-jenkins$ python3>>> import jenkins>>> server = jenkins.Jenkins('http://192.168.2.123: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[{'supportsDynamicLoad': 'MAYBE', 'downgradable': ...

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.