[英]Jenkins build step fails when calling "npm" on mac-os-x Yosemite
Before I start, I want to say that I already checked these answers:在开始之前,我想说我已经检查了这些答案:
Jenkins build step fails on 'npm install <whatever>' Jenkins 构建步骤在“npm install <whatever>”上失败
Jenkin's build failing on npm install Jenkins 在 npm install 上的构建失败
Now, I'm dealing with this issue for a while already and thus I tried a bunch of stuff.现在,我已经在处理这个问题一段时间了,因此我尝试了很多东西。
Firstly, I installed node + npm via homebrew.首先,我通过自制软件安装了 node + npm。 A simple $ node -v
and $ npm -v
echoed the version v0.10.36 for node and v2.3.* for npm, which also means I HAVE THEM IN THE PATH and they work while called in the terminal.一个简单的$ node -v
和$ npm -v
呼应了 node 的 v0.10.36 版本和 npm 的 v2.3.* 版本,这也意味着我有它们在路径中,它们在终端中调用时工作。
Simply adding node -v; npm -v
只需添加node -v; npm -v
node -v; npm -v
to the execute shell in Jenkins didn't do it. node -v; npm -v
到 Jenkins 中的执行 shell没有这样做。 After a bit of tinkering I copied what $: which node
yielded in the terminal to the above mentioned script, which now looked like this: /usr/local/bin/node
and apparently that worked.经过一番修改后,我将$: which node
在终端中产生的内容复制到上述脚本中,现在看起来像这样: /usr/local/bin/node
并且显然有效。 The Jenkins build succeeded and 'node-v0.10.36' was proudly displayed in the console output . Jenkins 构建成功,“node-v0.10.36”自豪地显示在控制台输出中。
When doing the same for 'npm' which happened to be /usr/local/bin/npm --version
the computing gods weren't so merciful anymore.当对恰好是/usr/local/bin/npm --version
的“npm”做同样的事情时,计算之神不再那么仁慈了。 A big ' env: node: No such file or directory ' error was thrown this time and the whole build failed.这次抛出了一个很大的 ' env: node: No such file or directory ' 错误,整个构建失败了。
The actual command that fails is $ /bin/sh -xe /var/folders/wr/g_dl81tn5_x0t_yz3jw602cr0000gn/T/hudson8770480548136671253.sh
and "surprisingly" when I run the same command in the terminal it succeeds.失败的实际命令是$ /bin/sh -xe /var/folders/wr/g_dl81tn5_x0t_yz3jw602cr0000gn/T/hudson8770480548136671253.sh
和“令人惊讶的是”当我在终端中运行相同的命令时它成功了。
I also uninstalled the homebrew node & npm versions and installed them afterwards via the package manager.我还卸载了自制节点和 npm 版本,然后通过包管理器安装它们。 Same results.结果相同。
Ultimately I also did this: https://gist.github.com/DanHerbert/9520689 , with no luck.最终我也这样做了: https ://gist.github.com/DanHerbert/9520689,没有运气。
Notes:笔记:
who am i
command inside the executable script yields the admin's user name.这恰好是 Jenkins 运行的同一用户,因为可执行脚本中的who am i
命令会生成管理员的用户名。Thanks a lot for your help, and let me know if you need any other info, screenshots, logs, etc.非常感谢您的帮助,如果您需要任何其他信息、屏幕截图、日志等,请告诉我。
I found my own solution.我找到了自己的解决方案。 The problem was that the PATH although visible in shell was not exported for the Jenkins job, and so, the first workaround, as found here, was to export it in the actual script like so:问题是 PATH 虽然在 shell 中可见,但没有为 Jenkins 作业导出,因此,在这里找到的第一个解决方法是将其导出到实际脚本中,如下所示:
but this feels like a hack!但这感觉就像一个黑客!
The right and elegant solution is to use Jenkins EnvInject Plugin and export the path in the added Properties content textarea on the configuration page, like so:正确而优雅的解决方案是使用 Jenkins EnvInject Plugin并在配置页面添加的 Properties 内容 textarea 中导出路径,如下所示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.