詹金斯无法找到 npm [英] Jenkins unable to find npm
问题描述
在这台 Linux 服务器上,我有一个名为myuser"的用户.对于这个用户,当回显路径时,我得到这个:
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
/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
它有效.
现在,我安装了 Jenkins.我要安装的 Jenkins 项目位于:
Now, I installed Jenkins. Jenkins project I'm trying to install is located at:
/var/lib/jenkins/workspace/test
构建正在执行一个 shell 脚本.在那个窗口我输入:
The build is executing a shell script. In that window I entered:
#!/bin/bash
npm i
与 Jenkins 一起构建时,我得到了这个:
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
如果我只写:
echo $PATH
在 Jenkins shell 中,我得到了这个:
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
如你所见,我安装了 nodejs 插件.无论如何,在使用 Jenkins shell 时,找不到 npm 甚至节点.我怎样才能让 Jenkins 知道 npm/node 在哪里?我试图先在 shell 中写这个:
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
$PATH=/home/myuser/.nvm/versions/node/v6.11.1/bin
但仍然没有运气.
推荐答案
我已经为此奋斗了一段时间.终于找到了解决办法.从您的作业菜单中选择 Configure
在 Build Environment
下选择 Provide Node &npm bin/文件夹到PATH
你可以保留默认设置,你很高兴.
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.
正如 Eric Wang 在评论中所指定的,需要先安装 NodeJS Plugin
才能出现此选项:https://wiki.jenkins.io/display/JENKINS/NodeJS+Plugin
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
这篇关于詹金斯无法找到 npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!