打赏
Fork me on GitHub

[原]jenkins(六)---jenkins远程部署脚本

/**

* lihaibo

* 文章内容都是根据自己工作情况实践得出。

* 版权声明:本博客欢迎转发,但请保留原作者信息!

http://www.cnblogs.com/horizonli/p/5332551.html

*/

 

在远程主机上创建一个shell脚本放置在自定义路径中:这里我放置在/opt下面:取名叫auto_deploy.sh

即:auto_deploy.sh在远程主机上什么位置,上图中的 Exec command 中就要写到哪个位置。

shell脚本怎么写可以自己定义:这里分享下自己写的脚本,以供参考:

#!/bin/bash
#Time
log_time=`date +[%Y-%m-%d]%H:%M:%S`

###manual_properties###
tomcat_basehome=/opt/tomcat6/apache-tomcat-6.0.45
tomcat_port=9090
shell_environment=/bin/bash
war_Dir=/opt/jenkins
war_Name=quick4j.war
###manual_properties###


#update server environment
echo "**********************************  ${log_time} *************************************"
echo "updating server  environment start"
export JAVA_HOME=/app/java/jdk1.8.0_11
export JRE_HOME=/app/java/jdk1.8.0_11/jre
export PATH=$JAVA_HOME/bin:$PATH 
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar/
export CATALINA_2_HOME=/opt/tomcat6/apache-tomcat-6.0.45
export CATALINA_2_BASE=/opt/tomcat6/apache-tomcat-6.0.45
export TOMCAT_2_HOME=/opt/tomcat6/apache-tomcat-6.0.45
sleep 3
echo "updating server  environment  end"

#build check funcation
echo "check tomcat status..."
check_tomcat_status(){
      netstat -ant|grep ${tomcat_port} > /dev/null 
      t=$?
       if [ $t -eq 0 ]; then
           echo "tomcat is running....port is ${tomcat_port}"
           echo "shutdown tomcat....."
           echo ">>>>>>>shutdown tomcat begin<<<<<<<<"
            ${shell_environment} ${tomcat_basehome}/bin/shutdown.sh
           echo ">>>>>>>shutdown tomcat end <<<<<<<<"
           sleep 5
       elif [ $t -ne 0 ];then 
             echo "tomcat is poweroff"
              ${shell_environment} ${tomcat_basehome}/bin/shutdown.sh
             sleep 5
       fi
} 

#check tomcat status invoke function
check_tomcat_status


#transfer  application package
deploy_Loaction=${tomcat_basehome}/webapps/
war_Dir_Data=`ls ${war_Dir}`
echo "--------------  begin  transfer  war package to tomcat webapps -------------------"

if [ -z $war_Dir ];then
     echo "Folder ${war_Dir} is empty.please check war package in this folder!"
     exit 1 
else
     echo "Find ${war_Dir} exist war package ${war_Name}"
    # echo "deleteing old  package ${war_Name} in ${war_Dir}"
    # rm ${war_Dir}/${war_Name}
     echo "deleteing old  package ${war_Name} in ${deploy_Loaction}" 
     rm ${deploy_Loaction}${war_Name}
     echo "start  transfer ${war_Name} to ${deploy_Loaction}"
     cp ${war_Dir}/${war_Name}  ${deploy_Loaction}
     sleep 3 
fi
echo "--------------  transfer  war package to tomcat webapps  end -------------------"
#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  **********************************"

 

 --------------------目录电梯---------------------

[原]Jenkins(一)---我理解的jenkins是这样的

[原]Jenkins(二)---jenkins之Git+maven+jdk+tomcat

[原]Jenkins(三)---Jenkins初始配置和插件配置

[原]Jenkins(四)---Jenkins添加密钥对

[原]jenkins(五)---jenkins添加项目

[原]jenkins(六)---jenkins远程部署脚本

[原]Jenkins(七)---jenkins项目编译测试发布由maven构建的web项目

[原]Jenkins(八)---jenkins构建项目报错时发送错误报告邮件

[原]Jenkins(九)---jenkins分别发布多个项目到多个远程主机

[原]Jenkins(十)---jenkins注册管理员admin并赋所有权限给admin

[原]Jenkins(十一)---jenkins使用管理员admin创建用户和分配权限

[原]Jenkins(十二)---jenkins管理员用户无法登陆解决办法Access Denied

[原]Jenkins(十三)---jenkins用户权限管理

[原]Jenkins(十四)---jenkins示例:admin管理所有项目,新建用户只能看部分项目

[原]Jenkins(十五)---jenkins插件之deploy

posted @ 2016-03-29 13:02  my_cool2007  阅读(10829)  评论(0编辑  收藏  举报