On this linux server, I have a user named "myuser". For this user, when echoing the path, I get this:
/home/myuser/bin:/home/myuser/.local/bin:/home/myuser/.nvm/versions/node/v6.11.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Having a node application, when deploying manually I run:
npm i
And it works.
Now, I installed Jenkins. Jenkins project I'm trying to install is located at:
/var/lib/jenkins/workspace/test
The build is executing a shell script. In that window I entered:
#!/bin/bash
npm i
When building with Jenkins, I get this:
[test] $ /bin/bash /tmp/jenkins756533162549346948.sh
/tmp/jenkins756533162549346948.sh: line 3: npm: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
If I only write:
echo $PATH
in the Jenkins shell, I get this:
[test] $ /bin/sh -xe /tmp/jenkins5067097808572366507.sh
+ echo /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
[test] $ /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/6.11.1/bin/node /tmp/jenkins8733250738704177758.js
Finished: SUCCESS
As you can see, I installed nodejs plugin. Anyway, when using Jenkins shell, the npm and even node are not found. How can I make Jenkins to know where npm/node is? I have tried to first write this in the shell:
$PATH=/home/myuser/.nvm/versions/node/v6.11.1/bin
But still no luck.
I have been battling with this for some time now. Finally found the solution. From your jobs menu select Configure
under Build Environment
select Provide Node & npm bin/ folder to PATH
You can leave the default setting and you are good to go.
As specified by Eric Wang in the comments, the NodeJS Plugin
needs to be installed first for this option to come up:
https://wiki.jenkins.io/display/JENKINS/NodeJS+Plugin
The answers in this thread didn't help me, what helped was adding the node.js tool to my Jenkinsfile:
pipeline {
agent any
tools {nodejs "nodejs"}
stages {
stage('Example') {
steps {
sh 'npm config ls'
}
}
}
}
Where the string "nodejs"
is the name
you give the node.js tool in the global tool configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With