#!/bin/bash
#tomcat 控制中心路径
tomcat_path=/usr/local/tomcat/apache-tomcat-9.0.7/webapps
#重启tomcat 的shell脚本
restart_tomcat_sh_path=/opt/run_/tomcat/general-control/
restart_tomcat_sh_name=restart.sh
#从git中下载的源码路径
# ${JENKINS_HOME} 为全局变量 请事先查看 有没有声明没有在 在/etc/profile中声明
# export JENKINS_HOME=/usr/local/tomcat/apache-tomcat-9.0.7/webapps
source_path=${JENKINS_HOME}"/workspace/equipments_manage"
project=equipments_manage
# war包路径 及 名称
war_path=${JENKINS_HOME}"/workspace/equipments_manage/service-module/remote-manager/target/"
war_name=mymanager.war
war_file=${war_path}${war_name}
# file_path=~/.jenkins/jobs/ManenDemo/workspace/equipments_manage/target
# 日志所在路径
log_file=${JENKINS_HOME}"/build_log.log"
#定义一个函数 用来写入log文件
writeLogFun(){
if [ ! -e $log_file ]
then
echo "文件不存在 新建一个"
touch ${log_file}
fi
nowtime=`date +%Y%m%d%H%M%S`
echo $nowtime$1 >> $log_file
}
writeLogFun "开始执行 mvn install命令当前路径$(pwd)"
# mvn install
mvn -f ${source_path}/pom.xml install
if [ -e $war_file ]
then
writeLogFun "检测到war包的存在"
#存在将 war包 移动到我的 tomcat 中
writeLogFun "移动${war_file}到${tomcat_path}"
mv ${war_file} ${tomcat_path}
sleep 1s
writeLogFun "移动到重启脚本路径下 启动脚本"
cd $restart_tomcat_sh_path
# . ./restart-all.sh #这个脚本是我用来重启tomcat的脚本 但我发现重启tomcat会导致请求502这是个坑
writeLogFun "执行 mvn clean"
mvn -f ${source_path}/pom.xml clean
else