Setup Jenkins to build python projects with tests

22 Jul

As I am currently part of a software project at university where we are developing some larger part of software in python I decided to locally install the whole continous integration chain at home. For the fun I am doing this on my Odroid U3 board which was also currently idling as my headunit project is on ice…

To get as near as real production chains are I am going to use jenkins for this task although there are many other python alternatives which could handle this much easier – but where is the fun then.

On my odroid is running the latest available image there which is Ubuntu 14.04.2 LTS with kernel. The system is only planned to do this one job therefore the OS is quite naked.


This tutorial is mainly based on steves tutorial which i tried to rewrite.


Get Jenkins

The first step was to get jenkins. Simply doing an “apt-get install jenkins” works but leaves you with some 2012 version of jenkins (1.4.something) from the official package list of ubuntu – which might be the most stable or whatever – but I want something new! Therefore you need to follow the instructions from jenkins site which is simply adding their own repository:

wget -q -O - | sudo apt-key add -
sudo sh -c 'echo deb binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

And afterwards jenkins should start up… In my case now version 1.609.


Get other tools

To get the source code everytime something changes we will us the state of the art: git. I think this is self explaining here.

For other parts of the jobs I want to get done by jenkins I’m mostly using the most common alternatives – to make it setup quick and hopefully without any major problems or disruptions. Therefore I am using:

  1. code management: “git”
  2. code coverage: “coverage”
  3. code quality: “pylint”
  4. unit tests: “unittest”
  5. testing: “nose”
  6. mocking: “mock”

All of this can easily pulled by:

sudo apt-get install python-mock python-nose python-coverage pylint git

Update Jenkins

I won’t bother with the part to init a new git because I already have something in the git. Therefore I’m just using this and going straight to configuring jenkins.
To get access to jenkins open your browser to the IP of the host system and add port 8080:jenkins_nakedI already made a first job so that it doesn’t looks empty.
To see the plugins, go to “Manage Jenkins” and select “Manage Plugins” (which is already marked red). Normally Jenkins already displays the plugins you need to update:jenkins_plugin_updatesSo select “Select All” at the bottom, click on “Download now… after restart” and let it work for some time. After this finished, check the checkbox at the end “… restart …” and select “back” above. Jenkins will now automatically restart and load the new plugin versions. Now we are at least up to date.

Install new plugins

 To get new plugins now, select “Available” at the top and choose the following:
  • Git Plugin
  • Cobertura Plugin
  • Violations
 and install them.
Afterwards go to the general “Configure System” tab and scroll down to “Git plugin” where you can enter the two following or other values:
  1. Global Config Value = Jenkins
  2. Global Config Value = Jenkins@localhost


Create Jobs

To create a job click on “New Item” and choose “Freestyle project” here.

jenkins_job_createCheck “Git” under “Source Code Management” and enter the repository URL and the necessary credentials.

The second part is to check the “Build Triggers” where we check “Poll SCM” and enter 5x* (* * * * *). This lets jenkins check the repository every minute for a new commit.

The third part is to configure the build itself. Therefore click on the dropdown “Add build step” under the “Build” section and select “Execute Shell”. Now paste the following into it:

nosetests --with-xunit --all-modules --traverse-namespace --with-coverage --cover-package=project1 --cover-inclusive
python -m coverage xml --include=project1*
pylint -f parseable -d I0011,R0801 project1 | tee pylint.out

To be continued…


One Reply to “Setup Jenkins to build python projects with tests”

Leave a Reply

Your email address will not be published. Required fields are marked *