For newcomers to the Linux environment, don't shoot the birds
Deployment environment and configuration: Tomcat9,maven3.3.9,git 1.12.0
# #定义一些变量, you will need to use the source directory, project directory, name, etc. to define variables, convenient usage
buildpkg=/mnt/xxx-tomcat-9.0.0.m4/gitsourcepkg/#git拉取源码存放目录buildpkgName =xxx-0.0.1-snapshot.war #maven打包后生成的 Package Name Targetpath=/mnt/xxx-tomcat-9.0.0.m4/gitsourcepkg/xxx/target/tbkmark-0.0.1-snapshot.war # The location of the package after Maven is packaged projectname=/mnt/xxx-tomcat-9.0.0.m4/gitsourcepkg/xxx #git拉下来的代码项目路径 and goes into the directory to execute MVN The package performs MAVEN packaged tomcatname=xxx #tomcat的名字, allowing you to query the specified tomcat process when multiple tomcat is in the same environment projectpath=/ Mnt/xxx-tomcat-9.0.0.m4/webapps/root #项目在tomcat中存放的路径startpath =/mnt/xxx-tomcat-9.0.0.m4/bin/startup.sh # Tomcat startup script Logpath=/mnt/xxx-tomcat-9.0.0.m4/logs/catalina.out #日志路径echo "##### start build xxx into the build directory, clean up the old data Pull Project # # # # # "CD $buildpkgrm-rf *git clone git link echo" ##### git pull ok git pulls the project finished, goes into the project directory to be packaged, and skips the test code ##### "CD $PROJECTNAMEMVN PA Ckage-dmaven.test.skip=trueecho "##### maven pkg OK package Successful after viewing the specified Tomcat process, and kill, and then the tomcat under the directory of the project is emptied, Copy the newly packaged project package to the specified directory under Tomcat and unzip the ##### "Ps-ef | grep Tomcat | grep $tomcatName | awk ' {print $} ' |xargs KILL-9CD $PROJECTPATHRM -RF *cp $targetpath $projectPathjar-xvf $buildpkgNameecho "##### kill Tomcat and CP pkg to root OK!!! Copy the production environment-specific profile, start Tomcat wait 5 seconds to view the log ##### "\cp/application.properties/mnt/xxx-tomcat-9.0.0.m4/webapps/root/web-inf/ Classes #\cp means that if there is a file with the same name in the target directory, it will be forced to overwrite, no longer remind Y/nsh $startpathsleep 5stailf-n $logpath
SVN chapter executes scripts from the deployment server to deploy the project to the production server
Projectname= Project name targetmathineme= project name targetmathine= target server SSH link path targettomcatwebappsdir= "~/xxx-tomcat-8.0.35/ WebApps "SVNPATH=SVN address checkoutdir=" Checkout "Targetwarname=war Package name MVN SCM:BOOTSTRAP-DCONNECTIONURL=SCM:SVN: $svnPath -dcheckoutdirectory= $checkoutDir-dgoals=package-dprofiles=skiptest,dev-dmavenhome= "" If [-f]./$checkoutDir/ target/$targetWarName. War "]; Thenecho "File xxx Generate success!" SCP $checkoutDir/target/$targetWarName. War $targetMathine: $targetTomcatWebAppsDir/$targetWarName. WAR.TMPSSH $ Targetmathine "MV $targetTomcatWebAppsDir/$targetWarName. war.tmp $targetTomcatWebAppsDir/$targetWarName. War" Fiecho "Xxx.war publish success."
Linux CentOS6.8 Project Deployment script implementation