Liunx上Jenkins 持续集成 Java + Maven + TestNG + Allure + Rest-Assured 接口自动化项目

文章目录

往期重点:

最新! 在 Linux上搭建Jenkins环境!

Jenkins邮件通知的详细配置含邮件通知模板!

Jenkin配置企业微信通知

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邮件通知的详细配置含邮件通知模板!

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

点击立即构建任务

查看邮件发送

查看邮件内容发送如下:

可能在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 接口自动化项目的操作细节。

相关推荐
曹牧1 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
爬山算法2 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?
java·后端·hibernate
kfyty7252 小时前
集成 spring-ai 2.x 实践中遇到的一些问题及解决方案
java·人工智能·spring-ai
猫头虎2 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
李少兄2 小时前
在 IntelliJ IDEA 中修改 Git 远程仓库地址
java·git·intellij-idea
忆~遂愿2 小时前
ops-cv 算子库深度解析:面向视觉任务的硬件优化与数据布局(NCHW/NHWC)策略
java·大数据·linux·人工智能
小韩学长yyds2 小时前
Java序列化避坑指南:明确这4种场景,再也不盲目实现Serializable
java·序列化
仟濹2 小时前
【Java基础】多态 | 打卡day2
java·开发语言
Re.不晚2 小时前
JAVA进阶之路——无奖问答挑战2
java·开发语言
Ro Jace3 小时前
计算机专业基础教材
java·开发语言