<plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>2.19.1</version>
                 <configuration>
                     <forkCount>3</forkCount>
                     <reuseForks>true</reuseForks>
                     <argLine>
                         -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                     </argLine>
                     <suiteXmlFiles>
                         <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
                     </suiteXmlFiles>
                     <testFailureIgnore>true</testFailureIgnore>
                     <systemProperties>
                         <propertiesFilePath>src/test/resources/allure.properties</propertiesFilePath>
                     </systemProperties>
                 </configuration>

                 <dependencies>
                     <dependency>
                         <groupId>org.aspectj</groupId>
                         <artifactId>aspectjweaver</artifactId>
                         <version>${aspectj.version}</version>
                     </dependency>
                 </dependencies>
             </plugin>
         </plugins>
     </build>
 ```
  • report: allure-maven

     <reporting>
             <excludeDefaults>true</excludeDefaults>
             <plugins>
                 <plugin>
                     <groupId>io.qameta.allure</groupId>
                     <artifactId>allure-maven</artifactId>
                     <version>2.10.0</version>
                     <configuration>
                         <reportVersion>${allure.version}</reportVersion>
                     </configuration>
                 </plugin>
             </plugins>
         </reporting>
    

    2.2 allure.properties

    allure.results.directory=target/allure-results
    allure.link.issue.pattern=https://example.org/issue/{}
    allure.link.tms.pattern=https://example.org/tms/{}
    

2.3 运行命令

  • mvn clean test -DsuiteXmlFile=src/test/resources/testng_sanity.xml

  • 生成allure报告:mvn io.qameta.allure:allure-maven:serve OR mvn io.qameta.allure:allure-maven:report

  1. Integrate with Jenkins

3.1 安装插件

Manage Jenkins -> Manage Plugins -> Allure Jenkins Plugin

3.2 配置插件

Manage Jenkins -> Global Tool Configuration -> Allure Commandline

allure

3.3 Job里面的配置

  • Post-build Actions -> Allure Report -> Path: target/allure-results

    Allure Report

  • Post-build Actions -> Editable Email Notification -> Default Content: ${SCRIPT, template=“allure-report.groovy”}

    • Email Extension
    • allure-report.groovy save in ${JENKINS_HOME}/email-templates (如果这个文件夹,新建一个就好了)

    Allure Email

  • allure-report.groovy

    https://gist.github.com/letsrokk/50a3ffc8ad5af8896ce78e62fe1e8cb5

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
     <style type="text/css">
     /*base css*/
         body
         {
           margin: 0px;
           padding: 15px;
         }
         
         body, td, th
         {
           font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Tahoma, sans-serif;
           font-size: 10pt;
         }
         
         th
         {
           text-align: left;
         }
         
         h1
         {
           margin-top: 0px;
         }
         a
         {
           color:#4a72af
         }
     /*div styles*/
         
     .status{background-color:<%= 
                 build.result.toString() == "SUCCESS" ? 'green' : 'red' %>;font-size:28px;font-weight:bold;color:white;width:720px;height:52px;margin-bottom:18px;text-align:center;vertical-align:middle;border-collapse:collapse;background-repeat:no-repeat}
     .status .info{color:white!important;text-shadow:0 -1px 0 rgba(0,0,0,0.3);font-size:32px;line-height:36px;padding:8px 0}
     </style>
     <body>
     <div class="content round_border">
                     <div class="status">
                             <p class="info">The build <%= build.result.toString().toLowerCase() %></p>
                     </div>
                     <!-- status -->
                             <table>
                                     <tbody>
                                             <tr>
                                                     <th>Project:</th>
                                                     <td>${project.name}</td>
                                             </tr>
                                             <tr>
                                                     <th>Build ${build.displayName}:</th>
                                                     <td><a
                                                             href="${rooturl}${build.url}">${rooturl}${build.url}</a></td>
                                             </tr>
                                             <tr>
                                                     <th>Date of build:</th>
                                                     <td>${it.timestampString}</td>
                                             </tr>
                                             <tr>
                                                     <th>Build duration:</th>
                                                     <td>${build.durationString}</td>
                                             </tr>
                                             <tr>
                                                     <td colspan="2">&nbsp;</td>
                                             </tr>
                                     </tbody>
         
                             </table>
                     <!-- main -->
             <% def artifacts = build.artifacts
                 if(artifacts != null && artifacts.size() > 0) { %>
         
                             <b>Build Artifacts:</b>
                             <ul>
                 <%          artifacts.each() { f -> %>
                     <li><a href="${rooturl}${build.url}artifact/${f}">${f}</a></li>
                 <%          } %>
                             </ul>
             <% } %>
       <!-- artifacts -->
         
     <% 
       lastAllureReportBuildAction = build.getAction(ru.yandex.qatools.allure.jenkins.AllureReportBuildAction.class)
       lastAllureBuildAction = build.getAction(ru.yandex.qatools.allure.jenkins.AllureBuildAction.class)
         
       if (lastAllureReportBuildAction) {
         allureResultsUrl = "${rooturl}${build.url}allure"
         allureLastBuildSuccessRate = String.format("%.2f", lastAllureReportBuildAction.getPassedCount() * 100f / lastAllureReportBuildAction.getTotalCount())
       }
     %>
     <% if (lastAllureReportBuildAction) { %>
     <h2>Allure Results</h2>
     <table>
                 <tbody>
                             <tr>
                                         <th>Total Allure tests run:</th>
                                         <td><a href="${allureResultsUrl}">${lastAllureReportBuildAction.getTotalCount()}</a></td>
                             </tr>
                             <tr>
                                         <th>Failed:</th>
                                         <td>${lastAllureReportBuildAction.getFailedCount()} </td>
                             </tr>
                             <tr>
                                         <th>Passed:</th>
                                         <td>${lastAllureReportBuildAction.getPassedCount()} </td>
                             </tr>
                             <tr>
                                         <th>Skipped:</th>
                                         <td>${lastAllureReportBuildAction.getSkipCount()} </td>
                             </tr>
                             <tr>
                                         <th>Broken:</th>
                                         <td>${lastAllureReportBuildAction.getBrokenCount()} </td>
                             </tr>
                             <tr>
                                         <th>Success rate: </th>
                                         <td>${allureLastBuildSuccessRate}%  </td>
                             </tr>
         
                 </tbody>
     </table>
     <img lazymap="${allureResultsUrl}/graphMap" src="${allureResultsUrl}/graph" alt="Allure results trend"/>
     <% } %>                  
       <!-- content -->
       <!-- bottom message -->
     </body>