装置插件
- 搜寻装置 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报告