2017-01-16 374 views
0

我已经阅读了大多数类似问题的答案,但没有一个适合回答我的问题。Jacoco代码覆盖率显示Jenkins覆盖率为0%

我在POM文件的个人资料如下:

  <plugins> 
       <plugin> 
        <groupId>org.jacoco</groupId> 
        <artifactId>jacoco-maven-plugin</artifactId> 
        <version>0.7.7.201606060606</version> 
        <executions> 
         <!-- Prepares the property pointing to the JaCoCo runtime agent which 
          is passed as VM argument when Maven the Surefire plugin is executed. --> 
         <execution> 
          <id>pre-unit-test</id> 
          <goals> 
           <goal>prepare-agent</goal> 
          </goals> 
          <configuration> 
           <!-- Sets the path to the file which contains the execution data. --> 
           <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile> 
           <!-- Sets the name of the property containing the settings for JaCoCo 
            runtime agent. --> 
           <propertyName>surefireArgLine</propertyName> 
          </configuration> 
         </execution> 
         <!-- Ensures that the code coverage report for unit tests is created 
          after unit tests have been run. --> 
         <execution> 
          <id>post-unit-test</id> 
          <phase>test</phase> 
          <goals> 
           <goal>report</goal> 
          </goals> 
          <configuration> 
           <!-- Sets the path to the file which contains the execution data. --> 
           <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile> 
           <!-- Sets the output directory for the code coverage report. --> 
           <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.19.1</version> 
        <configuration> 
         <skip>true</skip> 
        </configuration> 
        <executions> 
         <execution> 
          <id>surefire-unit-tests</id> 
          <phase>test</phase> 
          <goals> 
           <goal>test</goal> 
          </goals> 
          <configuration> 
           <!-- Sets the VM argument line used when unit tests are run. --> 
           <argLine>${surefireArgLine}</argLine> 
           <!-- Skips unit tests if the value of skip.unit.tests property is 
            true --> 
           <skipTests>${skip.unit.tests}</skipTests> 
           <!-- Excludes integration tests when unit tests are run. --> 
           <skip>false</skip> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-failsafe-plugin</artifactId> 
        <version>2.19.1</version> 
        <executions> 
         <!-- Ensures that both integration-test and verify goals of the Failsafe 
          Maven plugin are executed. --> 
         <execution> 
          <id>integration-tests</id> 
          <goals> 
           <goal>integration-test</goal> 
           <goal>verify</goal> 
          </goals> 
          <configuration> 
           <!-- Sets the VM argument line used when integration tests are run. --> 
           <argLine>${failsafeArgLine}</argLine> 
           <!-- Skips integration tests if the value of skip.integration.tests 
            property is true --> 
           <skipTests>${skip.integration.tests}</skipTests> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 

当我跑我的詹金斯的工作与Maven目标clean install -P test-coverage

我看到这在我的詹金斯登录:

`[JaCoCo plugin] Collecting JaCoCo coverage data... 
[JaCoCo plugin] **/target/coverage-reports/jacoco-ut.exec;**/target/classes;**/src/main/java; locations are configured 
[JaCoCo plugin] Number of found exec files for pattern **/target/coverage-reports/jacoco-ut.exec: 0 
[JaCoCo plugin] Saving matched execfiles: 
[JaCoCo plugin] Saving matched class directories for class-pattern: **/target/classes: 
[JaCoCo plugin] Saving matched source directories for source-pattern: **/src/main/java: 
[JaCoCo plugin] Loading inclusions files.. 
[JaCoCo plugin] inclusions: [] 
[JaCoCo plugin] exclusions: [] 
[JaCoCo plugin] Thresholds: JacocoHealthReportThresholds [minClass=0, maxClass=0, minMethod=0, maxMethod=0, minLine=0, maxLine=0, minBranch=0, maxBranch=0, minInstruction=0, maxInstruction=0, minComplexity=0, maxComplexity=0] 
[JaCoCo plugin] Publishing the results.. 
[JaCoCo plugin] Loading packages.. 
[JaCoCo plugin] Done. 
[JaCoCo plugin] Overall coverage: class: 0, method: 0, line: 0, branch: 0, instruction: 0` 

这是我为Jacoco配置的Jenkins配置:

enter image description here

+1

通告模式** /目标/覆盖的报表/ jacoco-ut.exec发现EXEC文件的行数':0'在詹金斯日志 - 你需要了解为什么没有这样的文件,它需要查看远远高于此行的构建日志。 – Godin

+0

@戈丁刚刚在那里取得了成功。实际上,构建目录与jenkins作业的工作空间不同。 – ASR

+0

还将exec文件位置更改为'**/jacoco.exec',最好遵循插件建议的内容。 – ASR

回答

0

在我的情况下,它是无法得到EXEC文件。

这是因为我的build目录是不同的,那么詹金斯作业的工作区。当我将构建目录更改为WORKSPACE时,发生了奇迹。

0

在我来说,我是用jacocoant 0.6和jaCoCo插件詹金斯2.2.0。 从jaCoCo插件github上页:

版本2.0.0或更高要求使用JaCoCo 0.7.5或更新的版本,如果你的项目仍然使用JaCoCo 0.7.4,该插件将不会显示任何代码覆盖的任何数字更多!在这种情况下,请使用版本1.0.19,直到您可以更新代码库中的jacoco。 https://github.com/jenkinsci/jacoco-plugin

0

在我的情况下,Jacoco插件是1.0.19,但我使用Jacoco - Maven的插件0.7.9,它是不兼容的。

所以,改变Jacoco - Maven的插件后0.7.4.x.我得到正确的覆盖上詹金斯