jenkins部署前端node項目實例
阿新 • • 發佈:2018-07-01
gre col 重啟 sta bubuko dep echo you shel
Jenkins 分發文件用到rsync命令
在 /etc/passwd中 修改 jenkins 為 /bin/bash
jenkins:x:494:494:Jenkins Automation Server:/var/lib/jenkins:/bin/bash
在客戶端
/etc/ssh/ssh_config 中修改
StrictHostKeyChecking no (去掉註釋)
在 jenkins 服務器切換到 jenkins賬戶 su - jenkins
創建密鑰
ssh-keygen
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa.
Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub.
將公鑰內容 id_rsa.pub 拷貝到客戶端 /root/.ssh/authorized_keys 文件內
將root賬戶公鑰 id_rsa.pub也拷貝到客戶端 /root/.ssh/authorized_keys 文件內
jenkins 具體配置
添加任務
general 中 描述寫 發布 ***** node 代碼
使用自定義的工作空間 /var/lib/jenkins/workspace/df-front
源碼管理:
設置 git 倉庫地址 , 賬戶密碼 ,倉庫分支
在構建 execute shell 分發文件到相應的服務器,並在對端服務器執行腳本npm i構建和重啟服務。
jenkins 服務器上腳本內容:
cat /data/sh/startnpm.sh #!/bin/bash cd /root/web source /etc/profile /usr/local/node-8.11.1/bin/npm i && EGG_SERVER_ENV=dev npm run start sleep 5 nodeport=` netstat -lntp|grep "8000"|awk ‘{print $4}‘|awk -F":" ‘{print $4}‘` echo $nodeport if [ "$nodeport" ];then echo-e "\033[32m[ node process start success on dev env ! ]\033[0m" fi
jenkins部署前端node項目實例