jenkins配置springboot項目啓動

一、建立項目 git地址設置

項目配置請參考

二、腳本編寫

#!/bin/bash
source /etc/profile
str=$"\n"
kill -9 $(sudo netstat -nlp | awk -F'[ /]*' '/8762/{print $(NF-2)}')
cp /home/wifilock/intelligent-family.jar /apps/intelligent-family
nohup java -jar intelligent-family.jar --spring.profiles.active=test -1 8 8 >/dev/null 1>intelligent-family.log &
sstr=$(echo -e $str)
echo $sstr
tail -20 intelligent-family.log

說明:java

  • source /etc/profile 加載環境變量,再部署時jenkins會報 「nohup: failed to run command java: No such file or directory 」 的錯誤,可是手動啓動腳本沒問題,加上後問題解決。
  • nohup 啓動項目後須要手動按回車才能正常啓動,在腳本中增長回車和輸出目錄操做,保證腳本自動啓動項目。

三、jenkins設置

jenkins部署時錯誤:

圖片描述

意思是:由於你是從一個非tty環境執行腳本;Jenkins不能正常從你的腳本中退出。
 解決辦法:

圖片描述

相關文章
相關標籤/搜索