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

相关推荐
深栈解码35 分钟前
JMM深度解析(三) volatile实现机制详解
java·后端
liujing102329291 小时前
Day04_刷题niuke20250703
java·开发语言·算法
Brookty1 小时前
【MySQL】JDBC编程
java·数据库·后端·学习·mysql·jdbc
能工智人小辰1 小时前
二刷 苍穹外卖day10(含bug修改)
java·开发语言
DKPT1 小时前
Java设计模式之结构型模式(外观模式)介绍与说明
java·开发语言·笔记·学习·设计模式
缘来是庄1 小时前
设计模式之外观模式
java·设计模式·外观模式
知其然亦知其所以然2 小时前
JVM社招面试题:队列和栈是什么?有什么区别?我在面试现场讲了个故事…
java·后端·面试
harmful_sheep2 小时前
Spring 为何需要三级缓存解决循环依赖,而不是二级缓存
java·spring·缓存
星辰大海的精灵2 小时前
如何确保全球数据管道中的跨时区数据完整性和一致性
java·后端·架构
大大。2 小时前
van-tabbar-item选中active数据变了,图标没变
java·服务器·前端