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

相关推荐
Yeh20205812 小时前
Mybatis笔记一
java·笔记·mybatis
likerhood12 小时前
Java 动态代理深度解析:从“为什么“到“底层原理“
java
_阿伟_12 小时前
信息检索简单介绍
java
下次再写12 小时前
深入浅出微服务架构:从理论到Spring Boot实战
java·微服务·springboot·springcloud·架构设计·后端开发·分布式系统
进阶的猿猴13 小时前
Rsa简单实现接口到期限制(springBoot)
java·spring boot·后端
雨落在了我的手上13 小时前
初识java(二):数据类型与变量
java·开发语言
小闫BI设源码13 小时前
当20个节点选出两个Master时:Elasticsearch的致命故障与解决方案
java·elasticsearch·jenkins·php·面试宝典·深入解析
醉颜凉13 小时前
Elasticsearch 核心原理:Posting List 倒排列表深度详解
大数据·elasticsearch·jenkins
SamDeepThinking13 小时前
千万级用户购物车系统的架构设计
java·后端·架构
liwulin050613 小时前
【JAVAFX】从ORACLE JDK切换到国内的JDK以便使用JAVAFX功能
java·数据库·oracle