6

I am trying to run webdriverio test from jenkins and following this . I installed nodeJS plugin for jenkins and under global tool config, for NodeJS , added a name and installation directory as /usr/local/bin (node executable is in this folder)

In Jenkins, in project config , under build environment, I have checked

Provide Node & npm bin/ folder to PATH and chosen the node installation name from previous step

But when I am trying to run npm install npm test ,by adding these commands under execute shell under Build and building it, I receive this error

Building in workspace /Users/Shared/Jenkins/Home/workspace/wdio-project
[wdio-project] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/hudson1478028169114509075.sh
+ npm install
/Users/Shared/Jenkins/tmp/hudson1478028169114509075.sh: line 2: npm: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
user1207289
  • 2,575
  • 4
  • 26
  • 54

6 Answers6

10

In case someone is looking for same issue, I resolved the above error by adding export PATH=/usr/local/bin to the execute shell under build. This post helped me

Community
  • 1
  • 1
user1207289
  • 2,575
  • 4
  • 26
  • 54
2

There is currently a bug opened about this (JENKINS-26583 and JENKINS-27170)

I could workaround this bug by adding explicitly node on the PATH by adding this line :

export PATH=$PATH:/home/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node_js/bin/
Rexave
  • 143
  • 1
  • 11
  • Just a note here that Jenkins home location and the node_js folder may vary depending on your local configuration. "node_js" folder carries the name configured in the Jenkins Global tool configuration. – Sorabh Mendiratta Aug 28 '18 at 07:37
0

I had just fixed the same issue as you did. I wonder if my fix would also help you. When I was using the alpine-based docker image, the Jenkins can never find the npm, but when I use the debian-based docker image, problem solved immediately.

Li Ke
  • 86
  • 1
  • 6
  • Did you do everything you said on mac os? if yes can you please share, how did you install debian based image on mac? – user1207289 Nov 21 '16 at 21:05
  • @user1207289 hi my host machine is a vps with centos 7.0 x64 – Li Ke Nov 21 '16 at 21:16
  • @user1207289 it might be the problem of permission and installation problem – Li Ke Nov 21 '16 at 21:17
  • thanks for commenting. ok, so, then yours was a linux. I am suspecting its not because of debian/alpine. though not fully sure. Was your way of `node.js` installation same as I described above? can you share if you did something else. I want to see if anything is missing in configuring `node.js` or in using this installation under `build environment` tab. – user1207289 Nov 21 '16 at 23:34
  • @user1207289 exactly the same, you could check if the environment path with the command "echo $PATH" and check if the node and npm is under the path directory or not. my problem with alpine is that the path is right and I could find the npm and node uder that directory, but couldnot find them with the command"where is npm" – Li Ke Nov 22 '16 at 21:40
  • when i did `which npm` it gave me `/usr/local/bin/npm` and I checked `/usr/local/bin` is in the `PATH` . I am not sure what else to check. `where is npm` gives me `command not found` – user1207289 Nov 23 '16 at 00:48
  • @user1207289 oh, then I dont know how to deal with that – Li Ke Nov 23 '16 at 00:49
0

Try this export PATH=/usr/local/bin:$PATH

neeraj-dixit27
  • 1,958
  • 12
  • 6
0

After installation of NodeJS restart pc

Anjan
  • 11
  • 1
0

In my case this worked -

export PATH=$PATH:/usr/local/bin

niku
  • 396
  • 2
  • 11