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

相关推荐
LiuYaoheng15 小时前
【Android】Android 的三种动画(帧动画、View 动画、属性动画)
android·java
lisanmengmeng15 小时前
apache-tomcat 安装部署
java·tomcat·apache
漫漫不慢.15 小时前
算法练习-二分查找
java·开发语言·算法
还是鼠鼠16 小时前
《黑马商城》Elasticsearch基础-详细介绍【简单易懂注释版】
java·spring boot·spring·elasticsearch·搜索引擎·spring cloud·全文检索
牧羊人_myr16 小时前
Maven核心功能与项目构建详解
java·maven
量子物理学16 小时前
Eclipse Mosquitto 在小内存下怎么修改配置文件
java·服务器·eclipse
惜.己16 小时前
linux中jenkins正常启动外部无法访问
linux·servlet·jenkins
程序员鱼皮16 小时前
让老弟做个数据同步,结果踩了 7 个大坑!
java·后端·计算机·程序员·编程·职场
Iris76117 小时前
MyBatis一对多关系映射方式
java
程序员清风17 小时前
滴滴二面:MySQL执行计划中,Key有值,还是很慢怎么办?
java·后端·面试