文章目录
- 往期重点:
-
- [jenkins 运行 Java + Maven + TestNG + Allure + Rest-Assured 接口自动化项目](#jenkins 运行 Java + Maven + TestNG + Allure + Rest-Assured 接口自动化项目)
- [可能在Jenkins + Maven 项目中遇到的错误](#可能在Jenkins + Maven 项目中遇到的错误)
-
- 遇到maven没有指定目标构建
- [遇到 mvn 命令找不到](#遇到 mvn 命令找不到)
往期重点:
Jenkins下载 Maven、Allure 插件并且配置环境
jenkins 运行 Java + Maven + TestNG + Allure + Rest-Assured 接口自动化项目
新建任务



选择你的仓库地址


执行测试用例的命令

由于我使用 java testng 框架,并且使用 testng.xml 文件管理我的测试用例,因此,我可以直接使用以下命令:
关于 testng.xml 如果管理测试用例相关配置可以参考:
一文搞定 Java + Selenium + TestNG + Allure 的框架搭建以及封装!
中的 testng.xml 部分

选择maven

这里是我们在Jenkins上配置的maven环境,如果不知道怎么配置,可以参考:
Jenkins下载 Maven、Allure 插件并且配置环境



添加allure报告
allure 的相关配置也可以参考:
Jenkins下载 Maven、Allure 插件并且配置环境



添加邮件通知
邮件的相关配置可以参考:

在任务中点击添加构建后的操作,添加邮件模板




点击立即构建任务


查看邮件发送
查看邮件内容发送如下:

可能在Jenkins + Maven 项目中遇到的错误
遇到maven没有指定目标构建
报错如下:
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: pre-clean, clean, post-clean, validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
Build step 'Invoke top-level Maven targets' marked build as failure
但是其实项目运行成功了,就是Jenkins报错,allure报告什么的都正常


那么该如何更改呢?

因此你需要在你的 pom.xml 文件中 添加如下内容
xml
<defaultGoal>compile</defaultGoal>
添加位置 需要在 build 之下
如:

此时再次构建,则没有问题

遇到 mvn 命令找不到
当你配置了你的maven的环境变量,并且虚拟机上也配置好了环境变量,·mvn -v
命令在虚拟机上也能够使用
此时查看Jenkins构建日志却出现以下错误:

此时需要我们在任务的配置当中,手动指定一下 maven path 环境变量


shell
export PATH=/usr/local/maven/apache-maven-3.9.9/bin:$PATH
echo $PATH
mvn -v
mvn clean test
再次构建则没有问题


以上就是在Liunx上 Jenkins 持续集成 Java + Maven + TestNG + Allure + Rest-Assured 接口自动化项目的操作细节。