打包配置
- httpclient测试代码打包:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>
./src/main/resources/testng.xml
</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
- springboot集成代码打包:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.test.StartApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>${project.basedir}/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
Jenkins--shell脚本
#/bin/bash
source /etc/profile
pid=$(ps x | grep "springbootTest-1.0-SNAPSHOT.jar" | grep -v grep | awk "{print $1}")
if [ -n "$pid" ] ; then
kill -9 $pid
fi
mvn clean package
pwd
cd target
BUILD_ID=dontKillMe
nohup java -jar springbootTest-1.0-SNAPSHOT.jar &
问题整理:
shell脚本踩坑记录:
对于上面的脚本,看网上的教程都是一样的写法,但是于我却总是有问题,找了很久的脚本问题终于知道原因,原来脚本对格式的限定很严格。
- 脚本中变量名和等号间不允许有空格
pid=$(ps x | grep "springbootTest-1.0-SNAPSHOT.jar" | grep -v grep | awk '{print $1}')
2.if判定条件中,“[”,“]”前后需要添加空格
if [ -n "$pid" ] ; then
3.PATH 命令覆盖
PATH='pwd' #报错代码
ps aux | grep -v grep | wc -l
test_path='pwd' #正确代码
ps aux | grep -v grep | wc -l
配置了脚本后,执行集成操作,Jenkins执行成功后,本地搭建的环境却无法通过IP访问,一直连接不到服务。后来查询发现在shell脚本是pre steps,完成后在build处还有操作,需要在goals and options添加脚本:
image.png
脚本配置参考:https://juejin.cn/post/7012971055182512135
持续集成终于让我搞定了,开心!
网友评论