Jenkins配合Shell脚本自动化部署Tomcat

#!/bin/bash
export BUILD_ID=dontKillMe
source /etc/profile
echo "删除旧部署目录"
rm -rf /usr/local/tomcat/webapps/ROOT
echo "复制war包到部署目录"
cd /var/lib/jenkins/workspace/skr/target/
cp skr.war /usr/local/tomcat/webapps/ROOT.war
echo "停止tomcat服务中......"
tomcat_pid=`ps -ef | grep tomcat | grep -v grep | awk '{print $2}'`
if [ -z $tomcat_pid ]; then
        echo "tomcat服务未启动"
else
        kill -9 $tomcat_pid
        sleep 5
        echo "停止tomcat服务成功"
fi
cd /usr/local/tomcat/bin/
./startup.sh
echo "tomcat启动中......"
TomcatServiceCode=0
while [ "$TomcatServiceCode" != "200" ]; do
sleep 3
TomcatServiceCode=$(curl -I -m 10 -o /dev/null -s -w %{http_code} http://localhost:9527)
done
echo "tomcat启动成功......"

你可能感兴趣的:(linux运维)