Jenkis is a great ci server with many options and plugins.
With a bit of time and configuration we can use Jenkins for our Node.js applications.
First of all the Node.js plugin on Jenkins enables us to run node.js scripts as a build step.
In order to proceeed executing various node.js tasks we can use shell build step.
The next step is to install packages using npm
The next problem is how to keep our application up and running.
To achieve this we can use forever.
Just add the latest version as a dependency inside your package.json
"dependencies": { "forever": "0.14.1" }
Then in the same build step we should stop any already running applications.
./node_modules/forever/bin/forever stopall
And by calling forever with BUILD_ID=dontKillMe in front of it we will ensure that Jenkins would not kill our node.js process running, which is most probably an application listening to a port.
BUILD_ID=dontKillMe ./node_modules/forever/bin/forever start bin/www
For unit testing I prefer the mocha framework.
xunit-file is a great plugin that will transform the results of mocha into a JUnit result file. Therefore we will add the mocha and xunit-file dependencies.
"dependencies": { "mocha": "~2.2.4", "xunit-file":"0.0.6" }
As a build step we should setup
./node_modules/.bin/mocha --recursive --reporter xunit-file
The xunit file produced on the workspace would be used from Jenkins in order to produce a JUnit report.
Therefore we should add a post build action to Jenkins that will publish the JUnit results.
Interesting article….