Dec
09
2018
0

How to setup a Python-Jenkins API connection with Python 3

Jenkins Dashboard

I’m working a project to create Python program that scrapes jobs from a Jenkins server, with the end goal of storing them in a Mongo NoSQL database as an archive.  At work we have more than a dozen build servers that will ultimately will be consolidated to a few. 

My plan(since we are moving to a cloud service)  is to use a Jenkins Docker container hosted from a cloud service to dynamically pull the jobs(from my MongoDB) and run builds on demand!

I decided to use the python-jenkins module, but immediately ran into problems.  Nothing serious, just tracking down a few libraries to build the Python modules acquired via pip3.  Afterward I tried to connect to a Jenkins server only to be denied with a 401 ‘invalid password’ error.  I spent all day trying to figure this one out, but there is little online to help.  All the examples I saw were Python2 with HTTPS configurations.  

Goals of this Post:

  • provide a clear example of connecting to Jenkins HTTP REST API via Python-Jenkins

Extra details:

  • Python 3.4, 3.5, 3.6 tested from Fedora 27 Client 
  • Python 3.5 tested from Fedora 24 Client
  • CentOS 6.10 – Jenkins Server ver 2.154
(more…)