Jenkins (VI)---Jenkins Remote deployment script

Source: Internet
Author: User

/**

* Lihaibo

* The content of the article is based on the practice of their own work.

* No reprint without the consent of the author

*/

Create a shell script on the remote host placed in the custom path: Here I placed under the/OPT: Take the name auto_deploy.sh

That is: where Auto_deploy.sh is located on the remote host, in the Exec command in which to write.

How the shell script is written can be defined by itself: Here are some of the scripts that you write, for your reference:

#!/bin/Bash#timelog_time=`Date+[%y-%m-%d]%h:%m:%S ' # # #manual_properties # # #tomcat_basehome=/opt/tomcat6/apache-tomcat-6.0. $Tomcat_port=9090shell_environment=/bin/Bashwar_dir=/opt/Jenkinswar_name=quick4j.war## #manual_properties # # #update Server EnvironmentEcho "********************************** ${log_time} *************************************"Echo "Updating server environment start"Export Java_home=/app/java/jdk1.8. 0_11export Jre_home=/app/java/jdk1.8.0_11/Jreexport 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. $Export Catalina_2_base=/opt/tomcat6/apache-tomcat-6.0. $Export Tomcat_2_home=/opt/tomcat6/apache-tomcat-6.0. $Sleep 3Echo "Updating server environment end"#build Check funcationEcho "check tomcat status ..."check_tomcat_status () {netstat-ant|grep${tomcat_port} >/dev/NULLT=$?if[$t-eq0]; 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-ne0]; Then              Echo "Tomcat is Poweroff"${shell_environment} ${tomcat_basehome}/bin/shutdown.SH             Sleep 5       fi} #check Tomcat status Invokefunctioncheck_tomcat_status#transfer Application Packagedeploy_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!"Exit1 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 fiEcho "--------------Transfer War package to Tomcat WebApps End-------------------"#reboot TomcatEcho ">>>>>>> 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 **********************************"

Jenkins (VI)---Jenkins Remote deployment script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.