wedriverio jenkins - npm command not found error
Asked Answered
T

6

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
Tonettetoney answered 8/11, 2016 at 20:21 Comment(0)
T
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

Tonettetoney answered 5/12, 2016 at 16:37 Comment(0)
S
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/
Stuartstub answered 19/3, 2017 at 20:43 Comment(1)
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.Mirthamirthful
V
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.

Vassallo answered 21/11, 2016 at 3:55 Comment(7)
Did you do everything you said on mac os? if yes can you please share, how did you install debian based image on mac?Tonettetoney
@Tonettetoney hi my host machine is a vps with centos 7.0 x64Vassallo
@Tonettetoney it might be the problem of permission and installation problemVassallo
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.Tonettetoney
@Tonettetoney 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"Vassallo
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 foundTonettetoney
@Tonettetoney oh, then I dont know how to deal with thatVassallo
C
0

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

Caraway answered 7/8, 2018 at 14:24 Comment(0)
H
0

After installation of NodeJS restart pc

Hawes answered 15/4, 2019 at 6:5 Comment(0)
V
0

In my case this worked -

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

Ventris answered 12/9, 2020 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.