Jenkins tomcat打包启动脚本,待完善
shell脚本
#!/bin/bash
JENKINS_HOME=/usr/local/jenkins
TOMCAT_HOME=/usr/local/jenkins/tomcat-test
SHUTDOWN=$TOMCAT_HOME/bin/shutdown.sh
STARTTOMCAT=$TOMCAT_HOME/bin/startup.sh
bin=${JENKINS_HOME}/tomcat-test/webapps
war=jidian-web.war
sleep 5
echo "=========================shutdown tomcat========================="
#$SHUTDOWN
#获取此tomcat进程并kill,awk ‘{print $2}’的含义是取前面查询结果的第二个分段,即pid
ps -ef|grep tomcat |grep $TOMCAT_HOME |grep -v 'grep'|awk '{print $2}' |xargs kill -9
sleep 5
#echo "Deploy ${war##*/}..."
echo "=========================copy war============================"
cp ${JENKINS_HOME}/workspace/xxx-test/xxx-web/target/xxx-web.war ${JENKINS_HOME}/tomcat-test/webapps
echo "=========================unzip ROOT============================"
rm -rf ${bin}/ROOT/ && unzip -qo ${JENKINS_HOME}/tomcat-test/webapps/${war} -d ${bin}/ROOT/
echo "=========================rm war=============================="
rm -f ${JENKINS_HOME}/tomcat-test/webapps/${war}
echo "=========================start tomcat============================"
$STARTTOMCAT
Jenkins配置
在jenkins中配置自动更新部署项目时,如果采取用execute shell启动/关闭tomcat,会发现可以进行关闭tomcat,但是无法启动tomcat,虽然构建会显示执行成功,但是查看进程,tomcat是没有启动的。这是因为Jenkins默认会在Build结束后Kill掉所有的衍生进程,所以要在前面加 BUILD_ID=DONTKILLME