打包配置
- 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腳本踩坑記錄:
對于上面的腳本没卸,看網(wǎng)上的教程都是一樣的寫法,但是于我卻總是有問題唠倦,找了很久的腳本問題終于知道原因菜枷,原來腳本對格式的限定很嚴格苍糠。
- 腳本中變量名和等號間不允許有空格
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
配置了腳本后岳瞭,執(zhí)行集成操作歹袁,Jenkins執(zhí)行成功后,本地搭建的環(huán)境卻無法通過IP訪問寝优,一直連接不到服務(wù)条舔。后來查詢發(fā)現(xiàn)在shell腳本是pre steps,完成后在build處還有操作乏矾,需要在goals and options添加腳本:
image.png
腳本配置參考:https://juejin.cn/post/7012971055182512135
持續(xù)集成終于讓我搞定了孟抗,開心!