Jenkins integration with Grunt

tempid picture tempid · Feb 13, 2014 · Viewed 36.1k times · Source

I've setup Jenkins v1.550 on Windows Server 2008 R2. It runs as a service at http://localhost:8080 for now. I'm logged into the machine as an Administrator. I've installed Node.js and can run "npm" from the command line.

I've also installed the NodeJS plugin v0.2.1 for Jenkins. I then went into the Configure System section of Jenkins, scrolled down to NodeJS installations, clicked on Add NodeJS button, gave "NodeJS" as the name, and "C:\Program Files\nodejs" as the path to the installation directory. I didn't check the "Install automatically" option as I read on the plugin page that it is only available to Linux.

I then created a new job, clicked the checkbox that said "Provide Node & npm bin/ folder to PATH", created a new build step for "Execute Windows batch command" and typed in "node --version" and "grunt --version" and saved it.

I ran the job and this is the output -

Building in workspace C:\Program Files (x86)\Jenkins\workspace\Test_1.0
[Test_1.0] $ cmd /c call C:\Windows\TEMP\hudson1381541243088903083.bat

C:\Program Files (x86)\Jenkins\workspace\Test_1.0>node --version 
v0.10.24

C:\Program Files (x86)\Jenkins\workspace\Test_1.0>grunt --version 
'grunt' is not recognized as an internal or external command,
operable program or batch file.

C:\Program Files (x86)\Jenkins\workspace\Test_1.0>exit 9009 
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

It looks like it's unable to find the grunt-cli for the user account Jenkins is running under (System). I tried to installing grunt cli globally (npm install -g grunt-cli) and also grunt locally (npm install grunt). No luck.

Can someone please help?

Answer

aqm picture aqm · Feb 25, 2014

for nice easy to configure self-installed nodejs on the machine, i have to recommend the excellent -> http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

it will install nodejs and grunt on the machine, through easy to use web front end no shell required

jenkins jobs can then simply run nodejs build steps, hey presto

steps involved :

a) install this on your jenkins instance -> http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

b) create a nodejs installation on jenkins

go to

http://URL_OF_JENKINS/jenkins/configure
  • NodeJS- > NodeJS installations -> Add NodeJS -> Name = "NodeJS 0.11.10", tick "Install automatically", select "Install from nodejs.org", add "grunt-cli" to globally installed packages

c) create a job with "execute NodeJS script" build task

var sys = require('sys');
sys.puts('NodeJS Test');
sys.puts('***************');
sys.puts('helloworld');

volia :)

run the job and see the nodejs script run,

from their the world is your oyster you can use grunt by ticking "Provide Node/npm bin folder to PATH" and running a "execute shell" build task

npm update
grunt
grunt --force reporting