安装插件
- 搜索安装 Allure Jenkins Plugin 插件
- Manage Jenkins -> Global Tool Configuration 的设置如下:
当Jenkins检测没有安装allure时,自动安装
POM配置
build -> plugins 编辑如下插件
<!-- JUnit单元测试 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <!-- 默认报告目录为 target/surefire-reports/ --> <!--reportsDirectory>target/test-reports/</reportsDirectory>--> <argLine> -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar </argLine> <properties> <property> <name>listener</name> <value>io.qameta.allure.junit4.AllureJunit4</value> </property> </properties> <systemProperties> <property> <name>allure.result.directory</name> <value>${project.build.directory}/allure-results/</value> </property> <property> <name>allure.link.issue.pattern</name> <value>http://example.org/issue/{}</value> </property> </systemProperties> </configuration> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectj.version}</version> </dependency> </dependencies> </plugin>
dependencies 添加如下依赖
<!-- Allure美化测试报告 --> <dependency> <groupId>io.qameta.allure</groupId> <artifactId>allure-junit4</artifactId> <version>2.9.0</version> <scope>test</scope> </dependency>
Notes: maven-surefire-plugin和allure-junit4需要添加对应的版本
Jenkinsfile
- Dashboard -> {项目名} -> {分支名} -> Pipeline Syntax,获取allure命令
修改 Jenkinsfile 如下
pipeline { agent any tools { maven "maven-3.6.3" } stages { stage ("UnitTest") { steps { configFileProvider([configFile(fileId: "mvn-setting-hhw", variable: "MVN_HHW")]) { sh "mvn -s ${MVN_HHW} test" } } } } post { always { script { allure includeProperties: false, jdk: '', results: [[path: 'target/allure-results/']] } } } }
sh "mvn -s ${MVN_HHW} test"
以指定的maven配置文件运行 test 任务post -> always -> script -> allure
在stages完成后总是运行allure操作
结果
- 构建结果如下
- Allure报告如下
点击Allure report
即可进入Allure报告
Junit5
pom.xml
->build
->plugins
<!-- JUnit单元测试 --> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>false</testFailureIgnore> <argLine> -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" </argLine> <systemProperties> <property> <name>junit.jupiter.extensions.autodetection.enabled</name> <value>true</value> </property> </systemProperties> <reportsDirectory>target/allure-reports/</reportsDirectory> </configuration> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-surefire-provider</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectj.version}</version> </dependency> </dependencies> </plugin> <plugin> <groupId>io.qameta.allure</groupId> <artifactId>allure-maven</artifactId> <version>2.10.0</version> <configuration> <reportVersion>2.4.1</reportVersion> </configuration> </plugin>
pom.xml
->dependencys
<!-- Allure美化测试报告 --> <dependency> <groupId>io.qameta.allure</groupId> <artifactId>allure-junit5</artifactId> <version>2.9.0</version> <scope>test</scope> </dependency>
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。