自动部署-jenkins安装使用

本文详细介绍了如何安装Jenkins并配置为使用Tomcat进行自动化部署,包括Jenkins版本选择、基础和全局配置步骤,以及通过脚本实现Tomcat应用的停启、备份和更新。内容涵盖Jenkins与Tomcat的集成,自动化部署流程,以及日志记录。
摘要由CSDN通过智能技术生成

1安装

1.1   jdk1.5以上。

1.2

  • jenkins.war    java -jar jenkins.jar--httpPort=8081
  •  tomcatjenkins.war用tomcat打开

  • 官网

           https://www.jenkins.io/zh/download/

  • 版本说明  

      LTS版本为稳定版,非LTS版本为测试版

  java 1.8  tomcat  8.0

2配置

 2.1 基础配置

 2.2全局配制

 tomcat配置、

 tomcat

deployTime=`date +'%Y%m%d%H%M%S'`
deployFormartTime=`date +'%Y-%m-%d %H:%M:%S'`
server_path='/usr/local/tomcat8'
jar_tep='/usr/local/appServer'
server_name='/usr/local/tomcat8/webapps/ROOT.war'
server_name_de='/usr/local/tomcat8/webapps/ROOT'
echo "开始执行$deployFormartTime" >> $jar_tep/log.txt
${server_path}/bin/shutdown.sh
tomcat_id=$(ps -ef |grep tomcat |grep -w ${server_path}|grep -v 'grep'|awk '{print $2}')
echo "开始关闭原有程序tomcat_id=$tomcat_id" >> $jar_tep/log.txt
if [ "$tomcat_id" == "" ]
  then
  echo -e "\033[32m已关闭Tomcat...\033[0m" >>  $jar_tep/log.txt
  else
  echo -e "\033[0m\033[32m强制关闭Tomcat...\033[0m"  >>  $jar_tep/log.txt
     sleep 1s
   ps -ef |grep tomcat |grep -w ${server_path}|grep -v 'grep'|awk '{print $2}'|xargs kill -s 9
  fi
echo "关闭原有程序完成" >> $jar_tep/log.txt
  sleep 500ms
tomcat_id=$(ps -ef |grep tomcat |grep -w ${server_path}|grep -v 'grep'|awk '{print $2}')
echo "关闭之后tomcat_id=$tomcat_id" >> $jar_tep/log.txt
mv  $server_name $jar_tep/${deployTime}.zip
echo "备份jar包完成" >> $jar_tep/log.txt
 mv ${server_path}/deploy/ROOT.war ${server_path}/webapps/ROOT.war
rm -r  $server_name_de
echo "删除ROOT完成" >> $jar_tep/log.txt
echo "移动jar包完成" >> $jar_tep/log.txt
  ${server_path}/bin/startup.sh  >> $jar_tep/log.txt   2>&1
 sleep 500ms
echo "启动jar包完成" >> $jar_tep/log.txt
tomcat_id=$(ps -ef |grep tomcat |grep -w ${server_path}|grep -v 'grep'|awk '{print $2}')
echo "启动之后tomcat_id=$tomcat_id" >> $jar_tep/log.txt
  sleep 500ms
echo "结束" >> $jar_tep/log.txt

jar

deployTime=`date +'%Y%m%d%H%M%S'`
server_path='/usr/local/tanker_server/mem'
jar_tep='/usr/local/tanker_server/mem/mem'
server_name='/usr/local/tanker_server/mem/memServer.jar'
echo "开始执行$tomcat_home" >> $jar_tep/log.txt
source /etc/profile
tomcat_id=$(ps -ef |grep $server_name|grep -v 'grep'|awk '{print $2}')
echo "开始关闭原有程序tomcat_id=$tomcat_id" >> $jar_tep/log.txt
ps -ef|grep $server_name|grep -v grep|awk '{print $2}'|xargs kill -s 9
echo "关闭原有程序完成" >> $jar_tep/log.txt
  sleep 500ms
tomcat_id=$(ps -ef |grep $server_name|grep -v 'grep'|awk '{print $2}')
echo "关闭之后tomcat_id=$tomcat_id" >> $jar_tep/log.txt

mv  $server_name $server_path/carTep/${deployTime}.zip

echo "备份jar包完成" >> $jar_tep/log.txt

mv $jar_tep/car.jar $server_name
echo "移动jar包完成" >> $jar_tep/log.txt
BUILD_ID=dontKillMe
nohup java -jar $server_name  --spring.profiles.active=test1 >  $server_path/logs/log.txt &
 sleep 500ms
echo "启动jar包完成" >> $jar_tep/log.txt
tomcat_id=$(ps -ef |grep $server_name|grep -v 'grep'|awk '{print $2}')
echo "启动之后tomcat_id=$tomcat_id" >> $jar_tep/log.txt
  sleep 500ms
echo "结束" >> $jar_tep/log.txt

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值