svn-maven-tomcat自动发布脚本
#!/bin/sh #svn-maven-tomcat自动发布脚本 #变量设置 svnpath=svn://10.60.10.120/研发部/xx-maven svnusername=xxx svnpassword=xxxn888 workplace=xxepp projname=xxepp tomcat_server=10.60.10.161 webappsPath=/usr/local/tomcat/webapps #环境变量设置 export JAVA_HOME=/usr/local/jdk18 export CLASSPATH=${JAVA_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH export M2_HOME=/usr/local/apache-maven-3.3.9 export M2=$M2_HOME/bin export PATH=$M2:$PATH rm -fr ${workplace} #从svn上面export代码 svn export ${svnpath} ./${workplace} --username ${svnusername} --password ${svnpassword} #maven编译 compileSuccessFlag=0 cd ${workplace} /usr/local/apache-maven-3.3.9/bin/mvn clean package -Dmaven.test.skip=true if [ $? -eq 0 ]; then compileSuccessFlag=1 echo "maven编译成功" else echo "maven编译失败" fi cd ../ #如果编译失败,直接退出 if [ ${compileSuccessFlag} -eq 0 ]; then echo "编译失败,程序退出" exit 1; fi #编译成功,war存在,则复制到tomcat目录,重启tomcat warPath=./${workplace}/target/${projname}.war if [ -f "${warPath}" ]; then #删除老的war包,将新的包拷贝过去 #ssh ${tomcat_server} rm -rf ${webappsPath}/${projname}.war ssh ${tomcat_server} find ${webappsPath}/old/ -mtime +7|xargs rm -rf ssh ${tomcat_server} mv ${webappsPath}/${projname}.war ${webappsPath}/old/${projname}$(date +%s).war ssh ${tomcat_server} rm -rf ${webappsPath}/${projname} scp ./${workplace}/target/${projname}.war ${tomcat_server}:${webappsPath}/ #重启tomcat echo "重启tomcat..." ssh ${tomcat_server} 'source /root/.bash_profile;/usr/local/tomcat/bin/shutdown.sh' sleep 3 if [ $? -eq 0 ]; then ssh ${tomcat_server} 'source /root/.bash_profile;/usr/local/tomcat/bin/startup.sh' sleep 6 echo "重启成功" else echo "tomcat启动失败" fi else echo "war包不存在" fi
备注:因maven服务器和tomcat服务器在不同的主机上,需要做公钥认证