Generic Web projects are deployed remotely to Tomcat via Jenkins and can be deployed using MAVEN's Tomcat-maven-plugin plug-in. Recently contacted with the deployment of the Spring boot project, because the spring boot app can use an internally integrated service container such as Tomcat, there is no need to deploy as originally. Take engineering Asset_web as an example, from Jenkins on a 120 server to 121.
Approximate steps:
- Jenkins gets the latest code from Git, compiles and packs;
- Deploy packaged jar packages to 121 servers;
- 121 The server shuts down the original app and then launches the new version.
The key point is the last point, which can be manipulated by scripting.
Build the deployment Run 1. Jenkins Configuration
System settings:
Add the SSH server, remote directory specifies the target path of the server to be deployed, tick use password***, enter the remote server password:
Project configuration:
- Build in Configure MAVEN command clean install deploy:
- In post-Build action, select Send build artifacts over SSH to configure the remote server that was previously added:
- With the 121 server selected, Source files specifies the build-to-run jar package with a value relative to the path: Asset_web/target/asset.jar (actual path/root/.jenkins/workspace/asset/asset_ web/target); Remote directory simply fills in "/", which references the path of the system configuration, and the Exec command can specify the run script, where the restart.sh script is run, and the Spring boot app is restarted to enable the new version.
2. Restart the script
First close the process for the project, and then start the new version of the app.
#restart.SH#!/bin/BashEcho "Restarting springboot application"PID=`PS-ef |grepAsset.jar |grep-Vgrep|awk '{print $}'`if[-N"$pid" ] Then Kill-9$pidEcho "To close a process:"$pidfiEcho "Grant Current user permissions"chmod 777/usr/src/springboot-app/Asset.jarEcho "Execute ..."Java-jar/usr/src/springboot-app/asset.jar
The problems encountered
1. Springboot package into jar after running prompt without master manifest attribute
Cause: Maven project does not inherit Spring-boot-starter-parent, which contains the MAVEN plugin Spring-boot-maven-plugin (package the project into an executable file, That is, specify the Main-class in the Manifest.mf file, which is the main portal when the jar is run.
Workaround: The plugin needs to be added to the build of the pom file, i.e.:
<Build> <Plugins> <plugin> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-maven-plugin</Artifactid> </plugin> </Plugins></Build>
2. When running the jar, the embedded tomcat default 8080 port is occupied and the port needs to be modified
There are three ways to modify the port ( Spring boot modifies the built-in Tomcat port number ), where it is convenient to add server.port=8180 in the profile application.properties.
3. Springboot Log Management
Log management and boot-features-logging for reference springboot (further in-depth study)
Reference:
- Https://www.cnblogs.com/niceboat/p/6230448.html
- https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-maven-without-a-parent
- Spring boot modifies the built-in Tomcat port number
- Log Management for Springboot
- Boot-features-logging
Jenkins Remote Deployment Springboot application