Java Jenkins 的构建在 npm install 上失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27661573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 04:48:27  来源:igfitidea点击:

Jenkin's build failing on npm install

javajavascriptnode.jsjenkinsnpm

提问by Matthew Harwood

I'm setting up an ubuntu server that has jenkins for CI.

我正在设置一个具有用于 CI 的 jenkins 的 ubuntu 服务器。

When I try to run a build I get failure

当我尝试运行构建时,我失败了

Question:How can I make npm installwork from my jenkins job?

问题:我怎样才能npm install从我的 jenkins 工作中工作?

build 1:

构建 1:

[morningharwood] $ /bin/sh -xe /tmp/hudson8925730298288495807.sh
+ pwd
/var/lib/jenkins/workspace/morningharwood
+ ls
bower.json
client
e2e
Gruntfile.js
karma.conf.js
package.json
protractor.conf.js
server
+ npm install
/tmp/hudson8925730298288495807.sh: 5: /tmp/hudson8925730298288495807.sh: npm: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Jenkin build enter image description here

詹金构建 在此处输入图片说明

UPDATE:

更新:

~$ pwd
/home/ubuntu

ls -a


.   .bash_history  .bashrc  .config    .gem    .gnupg  .node-gyp  .nvm      .rbenv  .ssh  .viminfo
..  .bash_logout   .cache   .dotfiles  .gemrc  .local  .npm       .profile  .rvm    .vim

Now that I see the .npm

现在我看到 .npm

+ /home/ubuntu/.npm/npm install
/tmp/hudson1456103398115324880.sh: 5: /tmp/hudson1456103398115324880.sh: /home/ubuntu/.npm/npm: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Configuration Script:

配置脚本:

enter image description here

在此处输入图片说明

What happens when you run from ssh terminal?

从 ssh 终端运行时会发生什么?

npm WARN engine [email protected]: wanted: {"node":"~0.8 || ~0.10"} (current: {"node":"0.11.14","npm":"2.0.0"})
npm ERR! Linux 3.13.0-36-generic
npm ERR! argv "/home/ubuntu/.nvm/v0.11.14/bin/node" "/home/ubuntu/.nvm/v0.11.14/bin/npm" "install"
npm ERR! node v0.11.14
npm ERR! npm  v2.0.0
npm ERR! path /var/lib/jenkins/workspace/morningharwood/node_modules
npm ERR! code EACCES
npm ERR! errno -13

npm ERR! Error: EACCES, mkdir '/var/lib/jenkins/workspace/morningharwood/node_modules'
...

So I've CHOWN the folder:

所以我已经CHOWN文件夹:

   + pwd
    /var/lib/jenkins/workspace/morningharwood
   sudo chown ubuntu /var/lib/jenkins/workspace/morningharwood/ -Rv
   ...

Ran npm install after that npm install

在 npm install 之后运行 npm install

It was successful!

成功了!

NEW PROBLEM:My build now fails when trying to clone the repository from github via jenkins.

新问题:尝试通过 jenkins 从 github 克隆存储库时,我的构建现在失败。

Console log

控制台日志

    Started by user matthew harwood
Building in workspace /var/lib/jenkins/workspace/morningharwood
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url [email protected]:matthewharwood/morningharwood.git # timeout=10
ERROR: Error fetching remote repo 'origin'
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

Showing owners:

显示所有者:

ls -la
drwxr-xr-x  3 jenkins jenkins 4096 Dec 26 20:31 .
drwxr-xr-x 13 jenkins jenkins 4096 Dec 26 08:23 ..
drwxr-xr-x  7 ubuntu  jenkins 4096 Dec 26 20:59 morningharwood

采纳答案by Sam Mikes

There are several problems here.

这里有几个问题。

It looks like you are using node0.11. Why? Do you need a feature from that unstable branch?

看起来您正在使用node0.11。为什么?你需要那个不稳定分支的特性吗?

If not, I would recommend using the nodesource packaged nodemodules, as described here: https://github.com/nodesource/distributions#usage-instructions

如果没有,我建议使用 nodesource 打包node模块,如下所述:https: //github.com/nodesource/distributions#usage-instructions

curl -sL https://deb.nodesource.com/setup | sudo bash - sudo apt-get install -y nodejs

curl -sL https://deb.nodesource.com/setup | sudo bash - sudo apt-get install -y nodejs

This will get you a good installation of nodeand npmin the global path, visible to both your ubuntuuser and the jenkinsuser.

这将使您在全局路径中获得良好的安装,node并且npm对您的ubuntu用户和jenkins用户都可见。

Finally, /home/ubuntu/.npm/npmis not an executable, but is the cached version of the npmpackage; /home/ubuntu/.npmis the per-user npm download cache.

最后,/home/ubuntu/.npm/npm不是可执行文件,而是npm包的缓存版本;/home/ubuntu/.npm是每个用户的 npm 下载缓存。

回答by Jigar Joshi

as it says

正如它所说

/tmp/hudson8925730298288495807.sh: 5: /tmp/hudson8925730298288495807.sh: npm: not found

npmisn't available in your path, so change your job to specify full path to npm

npm在您的路径中不可用,因此请更改您的工作以指定完整路径 npm

for example

例如

/usr/local/bin/npm install

or whereever npmis located

npm位于任何地方