Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins integration with Grunt

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?

like image 970
tempid Avatar asked Feb 13 '14 21:02

tempid


People also ask

Is grunt deprecated?

grunt. util. _ is deprecated and we highly encourage you to npm install lodash and var _ = require('lodash') to use lodash .

What is grunt used for?

Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile). Grunt was created by Ben Alman and is written in Node. js.

How do I add grunt?

The easiest way to add Grunt and gruntplugins to an existing package. json is with the command npm install <module> --save-dev . Not only will this install <module> locally, but it will automatically be added to the devDependencies section, using a tilde version range.


1 Answers

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
like image 96
aqm Avatar answered Oct 12 '22 15:10

aqm