1.本地发布脚本 publish.sh
#!/bin/sh currentDay=`date +%Y%m%d` currentTime=`date +%Y%m%d%H%M%S` tomcat1=/data/app/tomcat-contract confDir=/root/sh/config svnDir=/data/app/git/contract #echo ">>>>>>>>>>>>>>>>>>>>>>>>备份版本" #mkdir -p /data/app/tomcat-contract/backup/$currentDay #cp $svnDir/Bonade-Contract-Service/target/Bonade-Contract-Service.war /data/app/tomcat-contract/backup/20190109/"Bonade-Contract-Service_$currentTime".war #cp $svnDir/Bonade-Contract-Web/target/Bonade-Contract-Web.war /data/app/tomcat-contract/backup/20190109/"Bonade-Contract-Web_$currentTime".war echo ">>>>>>>>>>>>>>>>>>>>>>>>更新代码" cd $svnDir git fetch origin dev git checkout dev git pull sleep 10s echo ">>>>>>>>>>>>>>>>>>>>>>>>编译打包" mvn -U clean install -DskipTests -X #mvn -u clean install #sleep 120s echo ">>>>>>>>>>>>>>>>>>>>>>>>停止tomcat1" kill -9 `cat /data/app/tomcat-contract/temp/contract.pid` #sleep 5s echo ">>>>>>>>>>>>>>>>>>>>>>>>删除tomcat1下的文件" rm -rf $tomcat1/webapps/* echo ">>>>>>>>>>>>>>>>>>>>>>>>发布tomcat1" unzip $svnDir/Bonade-Contract-Service/target/Bonade-Contract-Service.war -d $tomcat1/webapps/Bonade-Contract-Service unzip $svnDir/Bonade-Contract-Web/target/Bonade-Contract-Web.war -d $tomcat1/webapps/Bonade-Contract-Web #清除多余的日志包 rm -f $tomcat1/webapps/Bonade-Contract-Service/WEB-INF/lib/slf4j-log4j12-1.7.5.jar echo "copy 配置文件" mkdir $tomcat1/webapps/Bonade-Contract-Web/WEB-INF/classes/config cp -rf $confDir/system.properties $tomcat1/webapps/Bonade-Contract-Web/WEB-INF/classes/config cp -rf $confDir/system.properties $tomcat1/webapps/Bonade-Contract-Service/WEB-INF/classes/config cp -rf $confDir/jdbc.properties $tomcat1/webapps/Bonade-Contract-Service/WEB-INF/classes/config #sleep 20s echo "启动服务" sh $tomcat1/bin/startup.sh
2.远程发布
#sftp上传应用包 sftp root@ip地址 << ! echo 上传service put /data/app/git/contract/Bonade-Contract-Service/target/Bonade-Contract-Service.war /data/app/tomcat-contract/backup/ echo 上传web put /data/app/git/contract/Bonade-Contract-Web/target/Bonade-Contract-Web.war /data/app/tomcat-contract/backup/ echo 上传结束
! #远程shell脚本执行发布 echo 执行发布 ssh root@129.204.115.46 "sh ~/sh/publish.sh" echo 发布完成
3.可以修改上面git 拉取分支,将分支参数化 ,这里如果改成在windows下使用doc命令传参就用 %1 获取参数。
git fetch origin $1 git checkout $1 git pull
执行 sh publish.sh dev 即可拉取dev分支, sh publish.sh test 拉取test分支
sh publish.sh dev