Jenkins自動部署NodeJs

Jenkins配置

一、打開系統設置中的全局工具配置,選擇新增NodeJs,選擇本身對應的版本後保存便可,我這裏別名直接用版本號代替了。node

二、打開系統設置中的配置,選擇增長SSH-Server,我選擇直接用用戶名登陸的,git

勾選Use password authentication, or use a different key,填寫對應帳號的密碼便可web

構建任務

一、新建任務,選擇構建自由風格的項目shell

二、源碼管理中填寫git地址並選擇本身對應的分支npm

三、構建環境中勾選Provide Node & npm bin/ folder to PATH,選擇本身對應的NodeJs服務器

四、構建,選擇執行shellide

選擇經過命令行發送文件工具

Source files:須要發送的文件,該路徑是本項目在Jenkins工做空間(workspace)下的相對路徑ui

Remove prefix:移除前綴,意思是去除路徑中的文件夾,只留下文件this

Remote directory:目標文件夾,該路徑是目標Tomcat所在服務器的root文件夾下的相對路徑

五、保存,構建看看結果,成功的話結果以下:

報錯

一開始老是下面這樣報錯

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了。

相關文章
相關標籤/搜索