Jenkins部署springboot项目

只写配置部分:踩了一天的坑,注意看构建的启动日志

#!/bin/bash
# 必须定义,如果不定义jenkins会在一个job执行完成后将tomcat程序杀死,造成程序无法再启动

# 定义变量
JAR_NAME="service-api.jar"
JAR_FILE=~/workspace/wisdom-vehicle/service-api/target/${JAR_NAME}
echo "lujin ${JAR_FILE}"
execute_target=~/service-api/
# 在部署前杀死上一次的程序
pid=$(ps -ef | grep ${JAR_NAME} | grep -v grep | awk '{print $2}')
if [ -n "${pid}" ]; then
  echo "kill -9 ${pid}"
  # grep ${JAR_NAME}    查询一个程序
  # grep -v grep 去除    grep
  # awk '{print $2}'    获取第二列数据
  # xargs kill -9       xargs可以将返回的数据传到给下一个命令使用
  ps -ef | grep ${JAR_NAME} | grep -v grep | awk '{print $2}' | xargs kill -9
fi
# 判定目录和文件是否存在
if [ ! -f ${JAR_FILE} ]; then
  echo "service-api.jar not exist!"
  exit
else
  if [ ! -d ${execute_target} ]; then
    echo "create directory:${execute_target}"
    mkdir -p ${execute_target}
  fi
  cp  ${JAR_FILE} /test/${JAR_NAME}
fi
# 部署新的程序
chmod 777 /test/service-api.jar
chmod 777 /logs/service-api/*
cd  /test/
echo "Go to the execution directory >> ${JAR_NAME}"
JENKINS_NODE_COOKIE=dontKillMe nohup java -jar service-api.jar --spring.profiles.active=prod >log.txt &
sleep 10
echo "Startup SpringBoot Application SUCCESS"

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值