首先保证你的jenkins插件和环境已经配置好,如果没有配置好可以看我之前的文章。。。此处略过
这里配置clean package可以保证清除旧的文件
这里使用over ssh,下篇文章部署jar将使用shell。
auto_deploy.sh
#!/bin/bash
echo "Start executing the script.........."
tomcat_port=8081
shell_environment=/bin/bash
tomcat_basehome=/home/server/apache-tomcat-8081
close_tomcat(){
netstat -ant|grep ${tomcat_port}
t=$?
echo $t
if [ $t -eq 0 ]; then
echo "tomcat is running....port is ${tomcat_port}"
echo "shutdown tomcat....."
${shell_environment} ${tomcat_basehome}/bin/shutdown.sh
echo ">>>>>>>shutdown tomcat begin<<<<<<<<"
sleep 5
elif [ $t -ne 0 ];then
echo "tomcat is poweroff"
fi
}
close_tomcat
echo "-----关闭tomcat函数执行完毕-----"
#reboot tomcat
echo " >>>>>>> rebooting tomcat begin <<<<<<<<"
${shell_environment} ${tomcat_basehome}/bin/startup.sh
echo " >>>>>>> rebooting tomcat end <<<<<<<<"
echo "the log you can read in canalina.out"
echo "************************ deploy war package into container Successlly **********************************"
然后需要在tomcat的server.xml里面配置项目的路径才可以成功启动访问。。。
(完)