Overall process
Every time the code changes on SVN, triggering the auto-build action, and deploying it to Tomcat on the server, the process is as follows:
1. Commit Code modification on SVN
2. Maven execution goals
3. Make the Web project into a war package
4. Shut down the server tomcat, copy the war package to the server Tomcat WebApps directory, start Tomcat
Project-related configuration
Because we are using MAVEN engineering, we can configure Pom.xml to focus on the configuration of build, as follows:
<Build> <Finalname>Dss</Finalname> <Plugins> <plugin> <Artifactid>Maven-compiler-plugin</Artifactid> <version>3.0</version> <Configuration> <Source>1.7</Source> <Target>1.7</Target> <encoding>UTF-8</encoding> </Configuration> </plugin> <plugin> <groupId>Org.apache.tomcat.maven</groupId> <Artifactid>Tomcat7-maven-plugin</Artifactid> <version>2.1</version> </plugin> <plugin> <Artifactid>Maven-antrun-plugin</Artifactid> <version>1.8</version> <Configuration> <Target> <AntAntfile= "./deploy/deploy.xml"> <Targetname= "Deploy" /> </Ant> </Target> </Configuration> </plugin> </Plugins> </Build>
With the Maven-antrun-plugin plugin, you can execute ant target, make it easy to copy files, execute SH scripts, Linux commands, and more . the target is defined here in the Deploy.xml file, as follows:
<?XML version= "1.0"?> <Projectname= "Deploy_war"default= "Deploy"Basedir="."> < PropertyEnvironment= "env"/> <Targetname= "Deploy"> <Echo>Start Deploy</Echo> <PathID= "Deploy.classpath"> <Filesetdir= "./deploy/lib"> <includename= "**/*.jar"/> </Fileset> </Path> <Taskdefname= "Sshexec"ClassName= "Org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"Classpathref= "Deploy.classpath" /> <Taskdefname= "SCP"ClassName= "ORG.APACHE.TOOLS.ANT.TASKDEFS.OPTIONAL.SSH.SCP"Classpathref= "Deploy.classpath" /> <Echo>Start stopping Tomcat</Echo> <SCPfile= "./deploy/stopdsstomcat.sh"Todir= "Root:[email protected]:/usr/local/dss-tomcat-7.0.47/bin"Trust= "true"/> <sshexecHost= "10.0.10.53"username= "root"Password= "123.com"Trust= "true"Command= "Cd/usr/local/dss-tomcat-7.0.47/bin;chmod 777 *.sh;./stopdsstomcat.sh" /> <Echo>Start copying War</Echo> <SCPfile= "./target/dss.war"Todir= "Root:[email Protected]:/usr/local/dss-tomcat-7.0.47/webapps"Trust= "true"/> <Echo>Start starting Tomcat</Echo> <sshexecHost= "10.0.10.53"username= "root"Password= "123.com"Trust= "true"Command= "Cd/usr/local/dss-tomcat-7.0.47/bin;". /STARTUP.SH;RM-RF stopdsstomcat.sh; "/> </Target> </Project>
A few notes:
1. Specify the dependent jar package path//path
2. Define a third-party task//taskdef
3. Upload the SH script to the remote server and execute the script (the script is mainly to close Tomcat and delete the war package under WebApps)//SCP sshexec
4. Copy the war package to the remote server
5. Launch Tomcat, deploy complete.
The sh script, which is used to close Tomcat and delete the war package, uses the way to kill the process instead of the Tomcat-shutdown script, because when Tomcat is closed, execution shutdown.sh will error:
#!/bin/bash#KillTomcat Piduser=`WhoAmI' Pidlist=`PS-ef|grepapache-tomcat-7.0. -|grep$USER |grep-V"grep"|awk '{print $}'`#PS-U $USER |grep "Tomcat"|grep-V"grep"if["$pidlist"="" ] Then Echo "no tomcat PID alive"Else forPidinch${pidlist} {Kill-9$pidEcho "KILL $pid:" Echo "Service Stop Success" }fiCD/usr/local/dss-tomcat-7.0. -/webapps/;RM-RF Dss.war;Echo "Remove Dss.war"RM-RF DSS;Echo "Remove DSS folder"
The above is the configuration of our project.
Jenkins Configuration
First, the download of the deployment Jenkins, is actually a Java Web project;
As for Jenkins configuration, it is mainly equipped with the interface:
We create a new MAVEN job, in the configuration interface:
Configuring JDK versions, SVN-related information
Configure the conditions that trigger the build
Configuring MAVEN-related information
Configuration End!!!
Project Continuous Integration Environment (Jenkins + SVN + maven + tomcat)