Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins script quitting prematurely when using npm install on Windows

In my Jenkins job I want to build a JavaScript app using Grunt. The Jenkins build scripts creates a build directory (if it doesn't already exist), changes to that directory and runs:

npm install grunt
npm install grunt-zip
grunt --gruntfile=[something]

(Of course grunt-cli is installed globally.) When I build the job, the first statement causes Grunt and dependencies to be pulled down as expected. However, the job then terminates successfully:

Archiving artifacts
No emails were triggered.
Finished: SUCCESS

The second npm install is not run. Any idea why the script is terminating after running npm install instead of continuing to the subsequent statements?

like image 788
Matthew Gertner Avatar asked May 31 '13 12:05

Matthew Gertner


People also ask

What is Prebuild NPM?

A command line tool for easily making prebuilt binaries for multiple versions of node, electron or node-webkit on a specific platform.

How do I stop NPM from installing?

You can stop the process on the console like any other process: Ctrl + c .


2 Answers

So it turns out that npm is a batch file, not an executable, so it needs to be invoked using call from the Jenkins script:

call npm install grunt
like image 187
Matthew Gertner Avatar answered Sep 24 '22 12:09

Matthew Gertner


i would recommend not using the local grunt / nodejs install, but instead getting jenkins to do this for you!

it's much easier and means there's less coupling to system specific installs and variables.

steps:

a) use nodejs jenkins plugin + get it to install nodejs on machine/grunt-cli -> Jenkins integration with Grunt

b) populate your package.json with any nodejs dependances required, eg grunt/grunt-zip etc

c) when running grunt just do a "npm update" before "grunt" command

that way your not doing explicit npm install, it's all configured from your package.json, and your build scripts will be less brittle, and your developers can use the same steps as the build server, eg "npm update;grunt" locally same as build server

like image 37
aqm Avatar answered Sep 25 '22 12:09

aqm