5

I'm trying to get a Jenkins build up and running on Cloudbees. I've successfully gotten NodeJs installed and my source pulled from my BitBucket repository. I am trying to run my grunt task to minify and concatenate my JS and CSS files before deploying. However, I am not able to run the grunt program, even though it is successfully installed. Below is my build script:

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.8.0 \
 source ./use-node
npm install
npm install grunt
grunt

I've tried installing grunt with and without the -g option without success. Here is the console output for the grunt portion of my build:

+ npm install grunt
...
npm http GET https://registry.npmjs.org/grunt
npm http 200 https://registry.npmjs.org/grunt
...
grunt@0.4.0 node_modules/grunt
├── dateformat@1.0.2-1.2.3
├── colors@0.6.0-1
├── hooker@0.2.3
├── eventemitter2@0.4.11
├── which@1.0.5
├── iconv-lite@0.2.7
├── coffee-script@1.3.3
├── lodash@0.9.2
├── nopt@1.0.10 (abbrev@1.0.4)
├── rimraf@2.0.3 (graceful-fs@1.1.14)
├── minimatch@0.2.11 (sigmund@1.0.0, lru-cache@2.2.2)
├── glob@3.1.21 (graceful-fs@1.2.0, inherits@1.0.0)
├── findup-sync@0.1.2 (lodash@1.0.1)
└── js-yaml@1.0.3 (argparse@0.1.12)
+ grunt
/tmp/hudson3382014549646667419.sh: line 8: grunt: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Any ideas on how to get this working? Is this even possible in Cloudbees?

Brady Isom
  • 1,635
  • 2
  • 13
  • 11

2 Answers2

5

Grunt is now broken up, annoyingly, into a separate cli module. Also, annoyingly, that cli module does not include grunt itself.

To make this work:

curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.8.0 \
 source ./use-node
npm install
npm install grunt
npm install grunt-cli
export PATH=$PATH:node_modules/grunt-cli/bin/
grunt

If the folk making this change how it works to be sensible, then it may change in future.

Docs here: http://gruntjs.com/getting-started

Michael Neale
  • 19,248
  • 19
  • 77
  • 109
  • Thank you, this got me past this hurdle. Kind of embarrassing that the answer was on the getting started page of GruntJs. – Brady Isom Mar 12 '13 at 03:08
  • 1
    It is a good Q - glad to have it here as I will no doubt forget ! I meant to look at grunt. Also - this was a recent change. Until recently what you had would almost work, but since grunt 4 - no such luck. Good luck ! – Michael Neale Mar 12 '13 at 03:59
  • Would love to hear of your progress with grunt.js - I am thinking of switching some clickstarts to use it instead of bash for some tasks. – Michael Neale Mar 12 '13 at 04:05
  • I've loved grunt so far. I haven't done anything very complex yet, but what I've used it for is working well. I've mostly just used it for minification and concatenation for production. – Brady Isom Mar 12 '13 at 20:16
  • 1
    I like the approach to separate the grunt-cli from the grunt version you're using in your project. It lets you have multiple version of grunt on a single machine. Would be great to have *js ready* slaves (node.js, phantomjs, npm, and some packages installed globally such as grunt-cli, bower, testacular, etc.) – xavier.seignard Mar 13 '13 at 13:34
  • good idea ... I will look into it. Generally we don't want to put everything everywhere all the time, but having some js flavour makes sense. – Michael Neale Mar 14 '13 at 09:12
0

you can setup everything from a jenkins job, no ssh/command line required:

Install Jenkins Plugins

  • Git Plugin - for git
  • Git Client Plugin - for git
  • Git Parameter Plugin - for git tags
  • GitHub API Plugin - for github
  • NodeJS Plugin - integration for common javascript tools NodeJS & npm

Git / Ant / Maven / NodeJS Installations

  • Goto SERVER/jenkins/configure
Git
  • Git -> Git installations -> Add Git -> JGit
  • Git plugin -> Global Config user.name Value = "Anthony Mckale", Global Config user.email Value = "anthony.mckale@bskyb.com"
NodeJS
  • 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

TADA

and hopefully git/nodejs and grunt will be available to you

see the plugin wiki for more details how to add the grunt/node tasks to the jenkins job -> https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

it's really easy :)

no ssh loggin required just jenkins admin rights

aqm
  • 2,942
  • 23
  • 30