根据jenkins centos环境搭建 docker及nodejs步骤

  • docker run -d --name jenkinsbuild_slave-python_upgrade -v /root/workspace/jenkins_build/jenkins_slave_nodejs_upgrade:/home/jenkins -v /var/run/docker.sock:/var/run/docker.sock myasuda/jenkins-centos-slave

-v /var/run/docker.sock:/var/run/docker.sock挂载docker目录,使容器内部可获取机器上的docker信息

  • yum install nodejs

  • yum install docker

  • yum install sudo

问题

  • npm run build报错
CentOS 7 使用 npm 失败 npm: symbol SSL_set_cert_cb
安装或更新openssl
yum -y install openssl
yum -y update openssl
  • CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x710f4c [node]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node]
 6: v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 7: 0x3ce18d9079a7
/home/jenkins/workspace/kanche-taurus@tmp/durable-e7c15344/script.sh: line 2:  1094 Aborted                 (core dumped) npm run build

解决方案:
替换容器 /usr/bin/node 二进制文件为 nodejs v8.9.1 版本二进制

  • Failed at the @ build script 'atool-build'
/home/jenkins/workspace/kanche-taurus/node_modules/atool-build/lib/build.js:148
    var _stats$toJson = stats.toJson(),
                              ^

TypeError: Cannot read property 'toJson' of undefined
    at doneHandler (/home/jenkins/workspace/kanche-taurus/node_modules/atool-build/lib/build.js:148:31)
    at /home/jenkins/workspace/kanche-taurus/node_modules/webpack/lib/MultiCompiler.js:104:18
    at /home/jenkins/workspace/kanche-taurus/node_modules/async/lib/async.js:52:16
    at /home/jenkins/workspace/kanche-taurus/node_modules/async/lib/async.js:361:13
    at /home/jenkins/workspace/kanche-taurus/node_modules/async/lib/async.js:52:16
    at done (/home/jenkins/workspace/kanche-taurus/node_modules/async/lib/async.js:241:17)
    at /home/jenkins/workspace/kanche-taurus/node_modules/async/lib/async.js:44:16
    at /home/jenkins/workspace/kanche-taurus/node_modules/async/lib/async.js:358:17
    at Compiler.<anonymous> (/home/jenkins/workspace/kanche-taurus/node_modules/webpack/lib/Compiler.js:185:21)
    at Compiler.<anonymous> (/home/jenkins/workspace/kanche-taurus/node_modules/webpack/lib/Compiler.js:265:19)

npm ERR! Linux 3.10.0-514.26.2.el7.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "build"
npm ERR! node v8.9.1
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! @ build: `atool-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ build script 'atool-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     atool-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs 
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls 
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/jenkins/workspace/kanche-taurus/npm-debug.log
[Pipeline] }
原因及解决方案:

jenkins目录下的文件及文件夹存在归属root权限的文件导致
将jenkins下的目录的所有者和组调整为jenkins
chown -R jenkins:jenkins jenkins

  • jenkins is not in the sudoers file. This incident will be reported
    为jenkins添加sudo权限