解决jenkins中npm install的symlink问题

问题

这一周在Jenkins上跑npm install经常会出现build fail,查了日志就是下面输出的样子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
npm ERR! node v4.4.7
npm ERR! npm v2.15.8
npm ERR! path ../gulp/bin/gulp.js
npm ERR! code EEXIST
npm ERR! errno -17
npm ERR! syscall symlink

npm ERR! EEXIST: file already exists, symlink '../gulp/bin/gulp.js' -> '/.jenkins/workspace/eshop/build/node_modules/.bin/gulp'
File exists: ../gulp/bin/gulp.js
Move it away, and try again.

npm ERR! Please include the following file with any support request:
npm ERR! /.jenkins/workspace/eshop/build/npm-debug.log
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.399 s
[INFO] Finished at: 2016-12-15T06:06:26+00:00
[INFO] Final Memory: 8M/63M
[INFO] -----------------------------------------------------------------------

一开始以为是建symlink的问题,考虑了可能权限或者symlink已存在的情况。但是用全新的一个虚机去跑npm install还是失败,错误有原因也是一样。本着死马当活马医的思路,加了一个-–no-bin-link参数,问题奇迹的解决了。查看官网的一段解释The --no-bin-links argument will prevent npm from creating symlinks for any binaries the package might contain.貌似也是在虚机才会出现这种情况。

之后又咨询了我们做构建的同事,他们建议把nodejs升级到6,同样也解决了问题。

总结

看来root cause是查不到了,只能给两个建议

  1. -–no-bin-link参数
  2. 升级Jenkins机器上的nodejs版本到6