Jenkin的构建在npm install上失败了

Mat*_*ood 10 javascript java node.js npm jenkins

我正在建立一个拥有jenkins for CI的ubuntu服务器.

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

问题: 如何npm install从我的詹金斯工作中完成工作?

构建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
Run Code Online (Sandbox Code Playgroud)

詹金建立 在此输入图像描述

更新:

~$ 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
Run Code Online (Sandbox Code Playgroud)

现在我看到了 .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
Run Code Online (Sandbox Code Playgroud)

配置脚本:

在此输入图像描述

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

npm WARN engine karma@0.12.28: 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'
...
Run Code Online (Sandbox Code Playgroud)

所以我已经把文件夹放到了:

   + pwd
    /var/lib/jenkins/workspace/morningharwood
   sudo chown ubuntu /var/lib/jenkins/workspace/morningharwood/ -Rv
   ...
Run Code Online (Sandbox Code Playgroud)

在npm install之后运行npm install

它很成功!

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

控制台日志

    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 git@github.com:matthewharwood/morningharwood.git # timeout=10
ERROR: Error fetching remote repo 'origin'
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)

显示所有者:

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
Run Code Online (Sandbox Code Playgroud)

Sam*_*kes 10

这里有几个问题.

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

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

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

这将为您提供良好的安装nodenpm全局路径,您的ubuntu用户和jenkins用户都可以看到.

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