保存当前工作状态 从 test 分支拉取最新代码 打包成war 发布到测试环境
解决:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#!/bin/bash # 20180125 保存当前工作状态 从 test 分支拉取最新代码 打包成war 发布到测试环境。 # 需要先配置 ssh auth 保证 ssh *** 免密登陆 export t=`date '+%y%m%d%H%M%S'` #测试环境 ssh export test_host=root@test.cn #测试环境 tomcat 地址 export tomcat_path=/home/apache-tomcat-8.0.36 #测试环境 war目录 export dest_path=$tomcat_path/webapps/ #保存工作目录状态 export branch_name=`git symbolic-ref --short -q HEAD` git stash save "deploy_test_$t" git checkout test && git pull &&\ mvn -DskipTests clean install && echo "开始上传" &&\ scp -P 4022 target/test.war "$test_host:~/test.war_$t" &&\ ssh -p 4022 $test_host $tomcat_path/bin/shutdown.sh sleep 5 export tomcatpid=`ssh -p 4022 $test_host ps aux |grep "$tomcat_path"|grep -v 'grep' |awk '{print \$2}'` ssh -p 4022 $test_host kill -9 $tomcatpid ssh -p 4022 $test_host cp "~/test.war_$t" $dest_path/test.war ssh -p 4022 $test_host $tomcat_path/bin/startup.sh #发布完成,恢复工作目录状态 git checkout $branch_name &&\ git stash pop |