Jenkins自动部署NodeJs

32次阅读

共计 1027 个字符,预计需要花费 3 分钟才能阅读完成。

Jenkins 配置

1、打开系统设置中的全局工具配置,选择新增 NodeJs,选择自己对应的版本后保存即可,我这里别名直接用版本号代替了。

2、打开系统设置中的配置,选择增加 SSH-Server,我选择直接用用户名登录的,

勾选 Use password authentication, or use a different key,填写对应账号的密码即可

构建任务

1、新建任务,选择构建自由风格的项目

2、源码管理中填写 git 地址并选择自己对应的分支

3、构建环境中勾选 Provide Node & npm bin/ folder to PATH,选择自己对应的 NodeJs

4、构建,选择执行 shell

选择通过命令行发送文件

Source files:需要发送的文件,该路径是本项目在 Jenkins 工作空间 (workspace) 下的相对路径

Remove prefix:移除前缀,意思是去除路径中的文件夹,只留下文件

Remote directory:目标文件夹,该路径是目标 Tomcat 所在服务器的 root 文件夹下的相对路径

5、保存,构建看看结果,成功的话结果如下:

报错

一开始总是下面这样报错

sh: /var/lib/jenkins/workspace/web_erp/node_modules/.bin/cross-env: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! sdhadmin@1.0.0 build:qa: `cross-env NODE_ENV=qa env_config=qa node build/build.js`
npm ERR! Exit status 126
npm ERR! 
npm ERR! Failed at the sdhadmin@1.0.0 build:qa script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /var/lib/jenkins/.npm/_logs/2019-06-04T02_24_47_411Z-debug.log
Build step 'Execute shell' marked build as failure

网上找了一圈资料没找到什么信息,试着把 node_modules 文件夹删掉再重新构建后就 ok 了。

正文完
 0