Javascript CI: JsLint recipe
Prerequisite:
Download jslint4java from https://code.google.com/p/jslint4java/ and extract the archive
To lint your code:
find . -iname "*.js" | xargs java -jar jslint4java.jar
What this command does is it
- uses the find command for collecting JS files recursively starting in the current directory:
find . -iname "*.js"
- pipes the resulting list of js files to xargs which will then run jslint4java on those files:
| xargs java -jar jslint4java.jar
- For CI you will also need to generate an xml report. This is easily done by using the —report xml flag:
java -jar jslint4java.jar --report xml > jslint.xml
In Hudson / Jenkins
- Add a new build step:
find . -iname "*.js" | xargs java -jar jslint4java-2.0.2/jslint4java-2.0.2.jar --report xml > jslint.xml
- Visualize the report with help of the Violations plugin
Additional notes:
- Use find -print0 together with xargs -0 if you have any directory names containing spaces:
find . -iname "*.js" -print0 | xargs -0 java -jar jslint4java.jar
- Use true or echo “lint completed” to prevent lint errors from breaking your build; it seems that otherwise Hudson / Jenkins will stop at that build step and not even create the violations report.
Jenkins and Pylint
Install pylint:
For some reason, installing pylint via pip crashed, however installing it using apt-get worked fine
melanie@mipu:~$ sudo apt-get install pylint
Running pylint:
melanie@mipu:~/pyProject$ find -iname "*.py" | xargs pylint -f parseable > pylint.txt No config file found, using default configuration
To make pylint stop complaining about the missing config file, generate one with the following command:
melanie@mipu:~/pyProject$ pylint --generate-rcfile > .pylint
Make sure to add the file to your repository so it’s available for your Jenkins build.
Modified command for running pylint together with your config file:
melanie@mipu:~/pyProject$ find -iname "*.py" | xargs pylint --rcfile=.pylint -f parseable > pylint.txt
Jenkins build step:
First step: Add Build Step > Execute Shell
Second step: Add the following command to Execute Shell > Command
#!/bin/bash find -iname "*.py" | xargs pylint --rcfile=.pylint -f parseable > pylint.txt echo "pylint complete"
Adding an echo as the last statement is only necessary if you want to use lint for analytical purposes only and not for deciding whether the build was successful or not. Also there’s probably a better way to find all python files e.g. by using python packages
Plot result with the violations plugin:
Install the Jenkins Violations plugin. Then back in your project add the name of the file generated by pylint to Post-builds Actions > Report Violations > pylint
Python CI with unit test result and coverage report
Plugins:
- Jenkins Mercurial plugin
- xUnit Plugin
- Jenkins Cobertura Plugin
Source Code Management:
Mercurial
- Repository URL, e.g. /home/melanie/pyProject
- Branch, e.g. default
Build Triggers:
- Poll SCM > Schedule, e.g.
15 * * * *
Build:
- Execute shell > Command:
nosetests --with-xcoverage --with-xunit
Post-build Actions:
- Publish Cobertura Coverage Report > Cobertura xml report pattern:
coverage.xml
- Publish JUnit test result report > Test report XMLs:
nosetests.xml
Installing, running and stopping Jenkins
melanie@mipu:~$ sudo apt-get install jenkins
I first tried running jenkins without root permission but that resulted in the following error message:
melanie@mipu:~$ service jenkins start start: Rejected send message, 1 matched rules; type="method_call", sender=":1.107" (uid=1000 pid=29374 comm="start jenkins ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
With root permission:
melanie@mipu:~$ sudo start jenkins jenkins start/running, process 8919
However, even after starting the server, jenkins was still unreachable; to get around that I had to update the JAVA_HOME variable in jenkins.conf:
from
/usr/lib/jvm/java-default (or default-java)
to
/usr
or actual path, e.g.
/usr/lib/jvm/java-6-openjdk
(source: How to start Jenkins?)
melanie@mipu:~$ sudo vim /etc/init/jenkins.conf
melanie@mipu:~$ sudo stop jenkins jenkins stop/waiting