关于jenkins:JenkinsAllure美化单元测试报告

7次阅读

共计 1769 个字符,预计需要花费 5 分钟才能阅读完成。

装置插件

  1. 搜寻装置 Allure Jenkins Plugin 插件
  2. Manage Jenkins -> Global Tool Configuration 的设置如下:

当 Jenkins 检测没有装置 allure 时,主动装置

POM 配置

  1. 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>
  2. 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

  1. Dashboard -> {我的项目名} -> {分支名} -> Pipeline Syntax,获取 allure 命令
  2. 批改 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 操作

后果

  1. 构建后果如下
  2. Allure 报告如下
    点击 Allure report 即可进入 Allure 报告
正文完
 0