Jenkins CI with Python and Github

This installation of Jenkins has Nosetests and Pylint with the Github and Git Plugins

This installation of Jenkins has Nosetests and Pylint with the Github and Git Plugins

NC State has a Github Enterprise installation that’s great for working on class projects, especially because it’s possible that some of your team-mates may be students studying remotely. It’s probably a good idea to use a server that will pull the latest changes from your master branches, run tests, and perform linting so that you know how well you’re progressing. Fortunately, all the tools for these are easily accessible. We used:

Installing software

  1. To start with, set up an organization in Github Enterprise for each course team we have and add your team-mates to it.

  2. Create a repository in Github Enterprise.

  3. Install Jenkins on your server.

  4. Install the Git Plugin for Jenkins. Optionally install the Github plugin as well. I didn’t use this for the CI features.

  5. Install the Violations plugin for Jenkins so we can report linting results.

  6. Create an SSH key-pair on your Jenkins server and set up the public key as a deploy key in the settings for your repository.

  7. Set up a web hook on Github Enterprise by going to the Service Hooks tab in the settings for your repository and picking the “Jenkins (Git Plugin)” option. Remember to set the URL to the base URL of your Jenkins installation.

  8. Add the deploy key to Jenkins credentials.

Jenkins Project Settings

  1. Under Source Code Management, select Git and specify the repository URL as specified on the Git Plugin page. This is currently the same URL you’d get if you selected the SSH option on the Github page for your project.

  2. Set the credentials to the key you’ll be using.

  3. In the Build Triggers section, pick the “Build when a change is pushed to Github” and “Poll SCM” options. Set the “Poll SCM” schedule to infrequent (it uses the same format as your crontab).

  4. For your build steps add the following for linting: (the echo command is to account for pylint returning non-zero unless you’re absolutely clean)

    find -iname "*.py" | xargs pylint --rcfile=.pylint -f parseable > pylint.xml || echo "pylint violations"

    and for testing, add:

    nosetests src/path/to/test/ --with-xunit
  5. Add a post-build option to “Publish JUnit Test Report” and specify **/nosetests.xml as the path.

  6. Add a post-build option to “Report Violations” and specify **/pylint.xml as the path.

  7. Add the Github Project URL if you want Github links.