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.45tomcat_port=9090shell_environment=/bin/bash
war_Dir=/opt/jenkins
war_Name=quick4j.war
###manual_properties###
#update server environmentecho"********************************** ${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.45export CATALINA_2_BASE=/opt/tomcat6/apache-tomcat-6.0.45export TOMCAT_2_HOME=/opt/tomcat6/apache-tomcat-6.0.45sleep3echo"updating server environment end"#build check funcationecho"check tomcat status..."check_tomcat_status(){
netstat -ant|grep${tomcat_port} > /dev/null
t=$?if[ $t -eq0];thenecho"tomcat is running....port is ${tomcat_port}"echo"shutdown tomcat....."echo">>>>>>>shutdown tomcat begin<<<<<<<<" ${shell_environment} ${tomcat_basehome}/bin/shutdown.shecho">>>>>>>shutdown tomcat end <<<<<<<<"sleep5elif[ $t -ne0];thenecho"tomcat is poweroff" ${shell_environment} ${tomcat_basehome}/bin/shutdown.shsleep5fi}
#check tomcat status invoke functioncheck_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 ];thenecho"Folder ${war_Dir} is empty.please check war package in this folder!" exit 1elseecho"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}
sleep3fiecho"-------------- transfer war package to tomcat webapps end -------------------"#reboot tomcat echo" >>>>>>> rebooting tomcat begin <<<<<<<<"${shell_environment} ${tomcat_basehome}/bin/startup.shecho" >>>>>>> rebooting tomcat end <<<<<<<<"echo"the log you can read in canalina.out"echo"************************ deploy war package into container Successlly **********************************"