1、安装配置
安装maven,配置maven环境变量
安装git
安装Jenkins
2、使用idea编辑器,springboot框架服务端代码,pom文件中编写maven插件和程序main函数入口类信息
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 指定SpringBoot程序的main函数入口类 -->
<mainClass>com.course.Application</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>
<!-- 打包本地jar包 -->
<extdirs>${project.basedir}/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
3、测试代码对应的pom文件里插件配置。
<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>
4、本地进行maven打包运行,看是否能正常跑通,正常后,在Jenkins上配置git地址,账号等信息,构建中执行execute shell进行shell脚本配置。
#!/bin/bash -il
/etc/profile
pid==$(ps x | grep "httpclientapply-1.0-SNAPSHOT.jar" | awk '{print $1}')
if [!-z "$pid"];then
echo "停止服务"
kill -9 $pid
else
echo "服务未启动"
fi
pwd
mvn clean package
cd target
pwd
BUILD_ID=dontKillMe
nohup java -jar httpclientapply-1.0-SNAPSHOT.jar &
5、build操作时,控制台输出情况如下,即为成功。
image.png
网友评论