Continuos Integration with Jenkins and Github and Karma
Hello all,
Continuos integration is an hot and complex topic, not my usual beginner tutorial. I found few documentation about this topic so i think it could be useful to give a direction to anyone who faces Jenkins for the first time and want to integrate it with a javascript project on github.
1. Requirements
- Unix machine with Jenkins (see part 3 for Jenkins installation and configuration), better on a public ip (optional)
- Github repository with Admin privileges and a dummy account
- Javascript project with karma (and it’s dependencies installed globally – mandatories: PhantomJS but can run with Chrome with extra effort)
After you setup everything except Jenkins proceed.
2. Starting Tips
- Jenkins can run anything, anytime you want inside a job, so the tutorial covers a javascript app with karma, but it can easily be a php webapp with phpunit. It’s just up to your job configuration/actions
- Karma is flexible, you can use any combination jasmine / mocha / chai / whatever, we’ll not cover how to unit test in this tutorial
- Code coverage, extended reports and other stuff are not covered.
Proceed.
3. Jenkins, Github installation and Configuration
- Follow the first 4 steps of this tutorial : https://strongloop.com/strongblog/roll-your-own-node-js-ci-server-with-jenkins-part-1/
Installation (same)
Security (same)
Installing Plugins + Github Pull Request Build Plugin
Integrating with GitHub - Configure a Jenkins Job as this tutorial says: http://kabisa.nl/building-github-pull-requests-with-jenkins/
- READ, REPEAT AND READ AGAIN THE MANUAL: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin
important parts:
– In “Branch Specifier”, enter “${sha1}”.
– Environment variables. - Check that your build configuration equals:
Advanced Project Options - Use custom workspace : /path/to/your/workspace/folder Source Code Management - Git -- Repository URL : https://github.com/username/repositoryName.git -- Credentials -- Name : aFictionalNameForJobVariable -- Refspec : +refs/pull/*:refs/remotes/origin/pr/* -- Branch specifier : ${sha1} Build Triggers - Build when a change is pushed to GitHub - GitHub Pull Request Builder -- Advanced --- (on) Build every pull request automatically without asking (Dangerous!). -- Whitelist Target Branches: (branches you are interested) Build - Set build status on GitHub commit - Execute shell : karma start /path/to/your/workspace/folder/karma.conf.js (this can be anywhere inside or outside the project) Post-build Actions - Set build status on GitHub commit - Github Pull Request Merger : Merge comment : Automatic tested merge of ${sha1}
- Make a pull requested on branches you are interested on github
It should work now, in the Global Configuration of Jenkins, under Github Pull Request Merger config you can decide if automatically merge.
Remember to add the application key of the dummy github account there.
That’s it,
Write a comment if something fails but i think it should be fine. 🙂
Hi, this is great, but it seems to insert an extra line break beetwen each line in the gist. The line numbers on the left are correct, but the gist itself extends way beyond them. It does it here on your site, and also when I try it on mine. Any ideas what might be causing that?