1

I'm trying to run grunt in jenkins (ubuntu), I already install nodejs plugin, then restarted jenkins. I create my job and inside of it I ticked under Build Environment the Provide Node & npm bin/ folder to PATH

Then in the Execute shell I run npm --version in sell my output is + npm --version 1.4.9, but if I run grunt --version, my output is grunt: not found.

I also tried in windows, in this case, I didn't install the nodejs plugin, I install everything from the bash command line. In this case I have this out put from jenkins for node and npm:

C:\Program Files (x86)\Jenkins\jobs\test-jenkins\workspace>node --version v0.10.29 C:\Program Files (x86)\Jenkins\jobs\test-jenkins\workspace>npm --version 1.4.14

and again for grunt: C:\Program Files (x86)\Jenkins\jobs\test-jenkins\workspace>grunt 'grunt' is not recognize as a command or a bash file

Lino
  • 295
  • 1
  • 5
  • 19
  • Have you installed grunt? `npm install -g grunt-cli` – dylants Jul 24 '14 at 19:22
  • Yes, I already installed grunt (npm install -g grunt) and grunt-cli (npm install -g grunt-cli) in windows. In Ubuntu I installed them through the nodejs plugin. – Lino Jul 24 '14 at 20:40
  • You've install the `grunt-cli` but you're saying the command `grunt` returns "'grunt' is not recognize as a command or a bash file". Have you had success with installing any other node modules globally on this machine? With the problem as it's described this might be a PATH issue more than a problem with Jenkins. – dylants Jul 24 '14 at 20:43
  • In the machine works, I'm running jenkins in my local machine, when I run grunt in my command line it works, but not when I try to run it from jenkins. In my user variables I have it in the path, but not in my ambient variables.So can be because of the path, what can I do? – Lino Jul 24 '14 at 20:47
  • For your local machine, which I assume is the Ubuntu machine, can you verify the user running Jenkins is the same as you? Or if not, that the user running Jenkins has access to the same `grunt` executable that you have? For Windows, you'll need to make sure the location of the `grunt.cmd` file is in your PATH. – dylants Jul 24 '14 at 21:17

2 Answers2

1

I manage to put this working only in Ubuntu.

I added the plugin nodejs to jenkins (jenkins -> manage plugins) and then restarted jenkins. After I went to my job, I checked the Provide Node & npm bin/ folder to PATH.Then I installed all the packages that I needed from the shell.

After that grunt worked fine.

Lino
  • 295
  • 1
  • 5
  • 19
0

The above problem comes up not only in linux but also in windows and here's a very simple solution which will work in most cases if you know where your grunt is installed. No need of installing any plugins.

As far as jenkins build is concerned it installs in drive:/.jenkins....../workspace/node_modules/.bin.

After providing this path in jenkins using shell script export path=$PATH:drive:/.jenkins....../workspace/node_modules/.bin, grunt started executing.

You can also check where the executable's are available on system path/ from where jenkins executes your executable's. Use which "executable_name" without qoutes. you can use this command both on windows as well as linux.

For complete reference: grunt-not-recognized-jenkins

Community
  • 1
  • 1
invinciblemuffi
  • 908
  • 1
  • 11
  • 22
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/11102851) – Toby Speight Feb 01 '16 at 13:28
  • @Toby Speight: Edited my answer to include more details as suggested, hope it helps others. – invinciblemuffi Feb 02 '16 at 05:15