Git自动化部署shell脚本

#!/bin/bash
echo "-------开始项目部署---------"
projectName="项目名称"
git_path="项目Git地址"
pid_no=$(ps -ef | grep tomcat | grep -v grep | awk '{print $2}');
if [ -n "$pid_no" ];then
 echo "杀死${projectName}进程的编号:${pid_no}"
 kill -9 "$pid_no"
 sleep 2
else
 echo "当前${projectName}项目已经被关闭"
fi
cd /opt/source
echo "当前${projectName}项目Git地址:" $git_path
read -t 30 -p  "请输入${projectName}项目的版本号,默认最新请直接回车跳过:" git_version
echo "移除${projectName}项目源码"
 rm -rf $projectName
 echo "拉取${projectName}分支项目"
 sleep 3
 git clone ${git_path} ${projectName}
 sleep 3
 cd ${projectName}
if [ -n "$git_version" ];then
 echo "开始切换到指定${git_version}版本号"
 git checkout $git_version
 git show $git_version > info.txt
 cat info.txt
else
 git show > info.txt
 cat info.txt
 echo "最新版本号"
fi
sleep 15
mvn clean -Dmaven.test.skip=true package
#nohup mvn tomcat7:run -Dspring.profiles.active=lml >/dev/null 2>&1 &
sleep 3
cd /usr/local/tomcat/tomcat/webapps
rm -rf ROOT ROOT.war
cp -r /opt/source/${projectName}/target/cqss-breakfast.war /usr/local/tomcat/tomcat/webapps/ROOT.war
cd /usr/local/tomcat/tomcat/bin
./startup.sh
time=$(date +"%Y-%m-%d")
tail -f /data/log/breakfast/logs/info.${time}.log

你可能感兴趣的:(Git自动化部署shell脚本)