前言
为了项目发布,老项目原本War
直接放到服务器上Tomcat
发布。由于Docker
只有Java
镜像改为Jar
,使用了Jenkins+SonarQube+Docker。这里描述一下流程,不会具体的描述Jenkins一些配置。
一、pom文件改造
<packaging>jar</packaging>
打包方式选择Jar
<build>
<finalName>xxx</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.xxx.main.MainApplication</mainClass>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
</build>
编译配置,由于老项目是JSP,所以需要打包webaapp
下资源文件。
<includeSystemScope>true</includeSystemScope>
如果项目采用了本地Jar导入,一定要加上这句。
二、Jenkins配置
1. 新建Maven项目

2.配置Git

3. 配置SonarQube


sonar.projectKey=xxx
sonar.sources=.
sonar.projectVersion=1.0
sonar.projectName=xxx
sonar.language=java
sonar.sourceEncoding=UTF-8
sonar.java.binaries=target/
sonar.java.binaries配置很重要。
4. 配置上传文件及执行Shell脚本


Source files: 需要上传的文件 如: target/projectName.version.jar
Remove prefix: 移除的前缀 如: target
Remote directory: 上传文件目标的服务器目录 如:usr/local/xxx
Exec command: 执行shell脚本的目标 如:/usr/local/xxx/server.sh
docker stop docker容器名称
docker rm docker容器名称
docker run --privileged=true --name docker容器名称 -d -p 8013:8080 -v /usr/local/xxx/xxx.jar:/mnt/app.jar java java -jar /mnt/app.jar
三、效果



四、总结
懂的都懂,网上都有。不是啥专业运维,只是记录一下踩坑日记。
网友评论