jenkins(六)---jenkins远程部署脚本

jenkins(六)---jenkins远程部署脚本_第1张图片


在远程主机上创建一个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远程部署脚本)