简体   繁体   English

Jenkins 构建步骤在“npm 安装”时失败<whatever> &#39;

[英]Jenkins build step fails on 'npm install <whatever>'

New to Jenkins: I am setting up our build in Jenkins. Jenkins 新手:我正在 Jenkins 中设置我们的构建。 Setting up a build step to run a nodejs script (a script to take the built app into a native iOS app, with Sencha Touch 2).设置构建步骤以运行 nodejs 脚本(使用 Sencha Touch 2 将构建的应用程序带入原生 iOS 应用程序的脚本)。 The nodejs script requires a wrench library. nodejs 脚本需要扳手库。

The Jenkins user appears to be running in a different context. Jenkins 用户似乎在不同的上下文中运行。 It couldn't see my node installation or npm installation.它看不到我的节点安装或 npm 安装。 As part of the build step, I had to export the path to node and npm.作为构建步骤的一部分,我必须将路径导出到 node 和 npm。 Now that I have done that, the build sees the node and npm commands.现在我已经这样做了,构建会看到 node 和 npm 命令。

However, one of the commands that I have it calling in the build step is 'npm install wrench' and it gives me a permissions error, and tells me to run as Administrator.但是,我在构建步骤中调用的命令之一是“npm install wrench”,它给了我一个权限错误,并告诉我以管理员身份运行。 So I can get it to work.所以我可以让它工作。

So I either need to be able to give the Jenkins user admin rights or I need to npm-install the package ahead of time for the user.所以我要么需要能够授予 Jenkins 用户管理员权限,要么我需要为用户提前 npm-install 包。 Does anyone know how to do either of those options.有谁知道如何做这些选项中的任何一个。

I am guessing you are running Jenkins on Mac and you have maybe installed it using the Jenkins Mac installer.我猜您正在 Mac 上运行 Jenkins,并且您可能已经使用 Jenkins Mac 安装程序安装了它。 I will further guess you installed it with default settings, which means Jenkins is set to run as a launch daemon and running under the account called daemon .我将进一步猜测您使用默认设置安装它,这意味着 Jenkins 设置为作为启动守护程序运行并在名为daemon的帐户下运行。

The daemon user is special.守护进程用户是特殊的。 It is very secure.这是非常安全的。 The home directory of the daemon user is owned by root and daemon has no write permission there, so it is unable to install anything there. daemon 用户的主目录归 root 所有,daemon 在那里没有写权限,因此无法在那里安装任何东西。

You can solve your problem by re-running the Jenkins installer but this time click on the Customize button.您可以通过重新运行 Jenkins 安装程序来解决您的问题,但这次单击“自定义”按钮。 Check the box that says Start at boot as "jenkins" .选中Start at boot as "jenkins"框。 Uncheck the box that says Start at boot as "daemon" .取消选中Start at boot as "daemon"框。

In build configuration add Execute command with export the path:在构建配置中添加带有导出路径的执行命令:

export PATH=/sbin:/usr/sbin:/bin:/usr/local/bin
npm install

For more information see this link有关更多信息,请参阅此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM