Jenkins + nodejs编译打包nodejs应用

NodeJs的镜像网址:https://npm.taobao.org/mirrors/node/latest-v6.x/

一、安装nodejs

下载nodes,并安装:

# cd /app/service_tools/
# wget https://npm.taobao.org/mirrors/node/v9.3.0/node-v9.3.0-linux-x64.tar.xz
# xz -d node-v9.3.0-linux-x64.tar.xz
# tar xf node-v9.3.0-linux-x64.tar

# ln -s /app/service_tools/node-v9.3.0-linux-x64 /app/service_tools/node-v9.3.0
# ln -s /app/service_tools/node-v9.3.0/bin/node /usr/bin/node
# ln -s /app/service_tools/node-v9.3.0/bin/npm /usr/bin/npm

如果可以查看到版本号证明安装成功:
[root@iZ256df41lxZ ~]# node -v
v9.3.0
[root@iZ256df41lxZ ~]# npm -v
5.5.1

有时候通过npm编译前端项目的时候出现报错:

npm ERR! path /app/Jenkins/.jenkins/workspace/test-marketweb-second/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/app/Jenkins/.jenkins/workspace/test-marketweb-second/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-06-12T09_51_48_611Z-debug.log
Build step 'Execute shell' marked build as failure
SSH: Current build result is [FAILURE], not going to run.
Finished: FAILURE

遇到这种问题可以尝试安装cnpm命令和webpack:

# npm install -g cnpm --registry=https://registry.npm.taobao.org
# ln -s /app/service_tools/node-v9.3.0/bin/cnpm /usr/bin/cnpm
# cnpm install webpack -g

Jenkins 配置:
在“系统管理”—>”Global Tool Configuration"中设置nodejs的安装方式,或者安装路径:

Jenkins + nodejs编译打包nodejs应用

一、新建项目选择“构建一个自由风格的软件项目”
Jenkins + nodejs编译打包nodejs应用

二、项目配置
在构建环境中设置环境为node环境

Jenkins + nodejs编译打包nodejs应用

构建命令:
Jenkins + nodejs编译打包nodejs应用

猜你喜欢

转载自blog.51cto.com/11019859/2128812