jenkins配置springboot项目启动

1、创建项目 git地址设置

项目配置请参考

2、脚本编写

#!/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

说明:

  • source /etc/profile 加载环境变量,再部署时jenkins会报 “nohup: failed to run command java: No such file or directory ” 的错误,但是手动启动脚本没问题,加上后问题解决。
  • nohup 启动项目后需要手动按回车才能正常启动,在脚本中增加回车和输出目录操作,保证脚本自动启动项目。

3、jenkins设置

 jenkins部署时错误:

 意思是:因为你是从一个非tty环境执行脚本;Jenkins不能正常从你的脚本中退出。
 解决办法:

你可能感兴趣的:(jenkins,springboot)