jenkins搭建可持续交付环境时,通过Send build artifacts over SSH部署tomcat到服务器的时,需要shell脚本,笔者空闲时间整理了一波,希望可以帮到后来的同学。配置如图:
在jenkins clean install 之后 打的war包会放到指定的文件夹内以 /save 为例,publish脚本如下:
#!/bin/bash
#make by
#time 2018/03/27
#version 0.1
#upgrade the project
#################定义变量#######################
instance="tomcat_eduop";
tomcat_progrm="/web/tomcat/tomcat_eduop";
bak_dir="/save";
export JAVA_HOME=/opt/soft/jdk1.8.0_91
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
################延时函数########################
function running(){
b=''
for ((i=0;i<=100;i+=2))
do
printf "progress:[%-50s]%d%%\r" $b $i
sleep 0.2
b=#$b
done
echo
}
echo "############# 重新部署 ##############";
rm -rf ${bak_dir}/op*
echo "########开始杀死tomcat进程,请等候5秒####################";
pid=$(ps aux|grep "java"|grep "$instance"|awk '{printf $2}');
if [ -n $pid ]; then
echo "tomcat pid: $pid";
kill -9 $pid;
fi
echo 'stop tomcat finished...'
echo 'backup old archive...'
running;
echo "####查看进程tomcat..";
ps -ef| grep "$instance" ;
echo "####重启tomcat...." ;
echo ${tomcat_progrm}/bin/startup.sh ;
${tomcat_progrm}/bin/startup.sh;
echo "###########启动成功#########" ;