记录学习Jenkins时,自动化部署tomcat项目的脚本。
新建 deploy.sh
脚本文件,文件内容如下:
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| #!/usr/bin/env bash
: << !
BUILD_ID=DONTKILLME
. /etc/profile
export PROJECT_PATH=/root/projects/java
export PROJECT_NAME=LoginDemo
export TOMCAT_PATH=/root/apache-tomcat-9.0.37
sh $PROJECT_PATH/$PROJECT_NAME/deploy.sh !
killTomcat() { pid=`ps -ef|grep tomcat|grep java|awk '{print $2}'` echo "tomcat Id list :$pid" if [ "$pid" = "" ] then echo "no tomcat pid alive" else kill -9 $pid fi }
rm -rf $PROJECT_PATH/$PROJECT_NAME
cd $PROJECT_PATH git clone git@gitlab.com:RainbowRing/LoginDemo.git
cd $PROJECT_PATH/$PROJECT_NAME mvn clean install
killTomcat
rm -f $TOMCAT_PATH/webapps/$PROJECT_NAME.war
cp $PROJECT_PATH/$PROJECT_NAME/target/$PROJECT_NAME.war $TOMCAT_PATH/webapps/
cd $TOMCAT_PATH/ sh bin/startup.sh
|