Jenkins + NodeJs

In this post i will explain how to integrate Jenkins with Nodejs.
Why Jenkis? Because it’s the most popular CI.

What is Jenkins?

Jenkins is a continuous integration application. The main features are:

  • Building/testing software projects continuously
  • Monitoring executions of externally-run jobs

More information here.

Pros:

  • Easy to learn
  • Open Source
  • Good Documentation & Tutorials
  • Plugins for everything

Cons:

  • 404: Not Found

Setup the Environment

Configure Jenkins

After the installation to check if everything is alright go to http://localhost:8080 by default is in port 8080. If everything is fine we should see this. (This is the new layout)

Jenkins

Now we should install the GIT plugin. To install plugins go to “Settings” menu and after “Plugins”.

After the installation we need to configure it. In the jenkins configuration, in the GIT section it’s necessary to put the path to the GIT CMD executable.

Jenkins GIT

Another required plugins for this tutorial:
Violations plugin
JSHint Report Plugin

Job

Job is a runnable task that is controlled/monitored by Jenkins. We are creating a job for our project.

1 – Create the Job

Create Job

2 – Configure the SCM (Source Control Management)

In our case we are using GIT but Jenkins also support SVN and mercurial.

Jenkins SCM

3 – Setup the build process

I created a npm task “jenkins”, this task runs an Grunt task. The task consist to running the tests and execute the JsHint to check code metrics.

Build Task

Package.json
gruntfile.js

4 – Post Build Actions

Here is the “key”, after the build are created two reports, one for tests and another for the jshint errors. The test report is compatible with JUnit test format, so the Jenkins can interpret. If all the tests are successful the build result is a success otherwise is a failure.

Report Plugins

Build Success

6 – JsHint Plugins

In the job page we can see the jshint report results.

Jshint

JsHint

Now you can integrate your nodejs projects in Jenkins 🙂

Leave a Reply

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

Connect with Facebook