sideroad

Setup Grunt on Jenkins

Grunt on Jenkins

Gruntis suitable for building JavaScript project as concat, minify, jshint and unit test.Jenkinsis suitable for CI as using SCM polling, scheduler. I think these tools makes our development faster. This is sample of front-end javascript project and building with Grunt on Jenkins.

Awesome project

src
Script files
dist
Compressed production files
dist/cov
Test coverage
dist/metrics
JavaScript static analysis
test
Test code
.jshintrc
jshint config file
Gruntfile.js
Grunt config file
package.json
Project config file
jenkins-grunt.sh
Kick grunt on jenkins

View sample code on GitHub

Gruntfile.js

Executejshint,testem,clean,qunit-cov,plato,concat,uglify

jshint

Detect errors and potential problems in JavaScript code and can be used to enforce coding conventions.

testem

Execute browser testing framework automatically. It's can be execute across a multitude of browsers and output the results in the TAP format.

clean

Cleaning production and coverage directiory before building

qunit-cov

Coverage unit test in qunit

plato

JavaScript source code visualization, static analysis, and complexity tool

concat

Concatenate files

uglify

Minify files with UglifyJS

jenkins-grunt.sh

  • Add node and phatomjs and jscoverage path to PATH environment variable.
  • Install node modules
  • Execute grunt
export PATH=/usr/local/bin:/path/to/node:/path/to/node_bin:/path/to/phantomjs:/path/to/jscoverage:$PATH;

npm install -g grunt-cli
npm install
grunt jenkins --no-color

Jenkins Configration

Install plugins

TAP Plugin

This plugin publishes TAP test results.

Create New Job

Jenkins->New job->Build a free-style software project

CreateNewJob

ClickAdd build step->Execute shelland inputsh jenkins-grunt.shinto Command area

ExecuteGrunt

ClickAdd post-build action->Publish TAP Resultsand inputtest/testem.tapinto Test results

PublishTAP

Build

Jenkins console output

JenkinsConsole

Tap results below

TAPResult

qunit-cov results below

Coverage Result

Plato results below

Plato Result

Comment