svn and maven 自動部署shell指令碼

天蠶峰發表於2015-09-09


通過svn獲取程式碼,然後maven編譯,釋出到jetty,然後重啟


#!/bin/sh
svnpath=http://192.168.1.121/svn/cate-manager/trunk
svnusername=yoursvnname
svnpassword=yousvnpwd
workplace=cate-manager
projname=cate-manager-web

deployPath=/home/work/jetty-80/webapps
stopShell="/home/work/jetty-80/bin/jetty.sh stop"
startShell="/home/work/jetty-80/bin/jetty.sh start"
restartShell="/home/work/jetty-80/bin/jetty.sh restart"

rm -fr ${workplace}

#從svn上面export程式碼
svn export ${svnpath} ./${workplace} --username ${svnusername} --password ${svnpassword}

#maven編譯
compileSuccessFlag=0
cd ${workplace}
mvn clean package -Dmaven.test.skip=true
if [ $? -eq 0 ]; then
compileSuccessFlag=1
echo "maven編譯成功"
else
echo "maven編譯失敗"
fi
cd ../

#如果編譯失敗,直接退出
echo ${compileSuccessFlag}
if [ ${compileSuccessFlag} -eq 0 ]; then
exit 1;
fi

#編譯成功,war存在,則複製到jetty目錄,重啟jetty
warPath=./${workplace}/${projname}/target/${projname}.war
if [ -f "${warPath}" ]; then

#刪除老的war包,將新的包拷貝過去
rm -f ${deployPath}/root.war
cp ./${workplace}/${projname}/target/${projname}.war ${deployPath}/root.war

#重啟jetty
echo ${restartShell}
${restartShell}

else
echo "war包不存在"
fi
echo "deploy success"


相關文章