当调用"npm"时,Jenkins构建步骤失败.在mac-os-x优胜美地上 [英] Jenkins build step fails when calling "npm" on mac-os-x Yosemite

查看:105
本文介绍了当调用"npm"时,Jenkins构建步骤失败.在mac-os-x优胜美地上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开始之前,我想说我已经检查了以下答案:

Before I start, I want to say that I already checked these answers:

在'npm install< whatever>'上,Jenkins构建步骤失败

詹金(Jenkin)的构建在npm安装上失败

现在,我已经处理了一段时间,因此尝试了很多东西.

Now, I'm dealing with this issue for a while already and thus I tried a bunch of stuff.

首先,我通过自制软件安装了node + npm.一个简单的$ node -v$ npm -v回显了node的v0.10.36版本和npm的v2.3.*版本,这也意味着我已经将它们保存在路径中,并且它们在终端中被调用时可以正常工作.

Firstly, I installed node + npm via homebrew. 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.

仅在Jenkins的 执行shell 中添加node -v; npm -v即可.稍作修改后,我将终端中的$: which node生成的内容复制到上述脚本中,该脚本现在看起来像这样:/usr/local/bin/node,并且显然起作用了. Jenkins构建成功,并且在 控制台输出 中自豪地显示了"node-v0.10.36".

Simply adding node -v; npm -v to the execute shell in Jenkins didn't do it. 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. The Jenkins build succeeded and 'node-v0.10.36' was proudly displayed in the console output.

当对'npm'进行同样的操作时,恰好是/usr/local/bin/npm --version,计算神不再那么仁慈.这次抛出了一个大的" env:节点:没有这样的文件或目录"错误,整个构建失败了.

When doing the same for 'npm' which happened to be /usr/local/bin/npm --version the computing gods weren't so merciful anymore. A big 'env: node: No such file or directory' error was thrown this time and the whole build failed.

失败的实际命令是 $ /bin/sh -xe /var/folders/wr/g_dl81tn5_x0t_yz3jw602cr0000gn/T/hudson8770480548136671253.sh和令人惊讶地",当我在终端中运行相同的命令时,它会成功.

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.

我还卸载了自制节点& npm版本,然后通过程序包管理器进行安装.结果相同.

I also uninstalled the homebrew node & npm versions and installed them afterwards via the package manager. Same results.

最终我也这样做了: https://gist.github.com/DanHerbert/9520689,没有运气.

Ultimately I also did this: https://gist.github.com/DanHerbert/9520689, with no luck.

注释:

  • 我正在运行Jenkins 1.613,并尝试使用1.5 **
  • 我没有创建"Jenkins"特定用户,而是使用管理员.这恰好是Jenkins运行的同一用户,因为可执行脚本中的who am i命令会产生管理员的用户名.
  • sudo'ing无济于事
  • 我也在虚拟环境中运行整个过程-无所事事
  • 我不是将Jenkins作为守护进程运行,因为它与xtools冲突,而是作为一个简单的过程
  • 我还尝试了具有各种配置的jenkins-node插件(如果需要,可以提供详细信息)
  • I'm running Jenkins 1.613 and tried with 1.5**
  • I didn't create a "Jenkins" specific user but instead I'm using the admin. This happens to be the same user that Jenkins runs, since the who am i command inside the executable script yields the admin's user name.
  • sudo'ing doens't help
  • I'm also running the whole thing in a Virtual Environment - vagrant
  • I'm not running Jenkins as a deamon, as it's conflicting with xtools, but as a simple process
  • I also tried out jenkins-node plugin with various configs (can detail if needed)

非常感谢您的帮助,如果您需要其他任何信息,屏幕截图,日志等,请告诉我.

Thanks a lot for your help, and let me know if you need any other info, screenshots, logs, etc.

推荐答案

我找到了自己的解决方案.问题在于,尽管在Shell中可见的PATH并未为Jenkins作业导出,因此,这里找到的第一个解决方法是将其导出为实际的脚本,如下所示:

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:

但这感觉就像是骇客!

but this feels like a hack!

正确而优雅的解决方案是使用Jenkins EnvInject插件,然后在配置页面上添加的属性"内容文本区域中导出路径,如下所示:

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:

这篇关于当调用"npm"时,Jenkins构建步骤失败.在mac-os-x优胜美地上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆