从詹金斯(Jenkins)的Jacoco报道中排除包裹 [英] Exclude package from Jacoco coverage in Jenkins

查看:685
本文介绍了从詹金斯(Jenkins)的Jacoco报道中排除包裹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Jenkins管道失败,尝试从覆盖率报告中排除软件包.我有一个包含所有POJO的子项目.我不想为所有这些编写uittest.因此,他们将下拉分支/行覆盖率,以使覆盖率低于阈值并导致构建失败.

Trying to exclude packages from coverage report as my Jenkins pipeline fail. I have a sub project with all POJO:s. I don't want to write uittest for all these. Hence, they will drag down branch/line coverage som that coverage will be below threshold and fail my build.

应该可以排除某些软件包,但我无法使其正常工作.

It should be possible to exclude some packages, but I cant get it to work.

我有以下jacoco.gradle文件:

I have the following jacoco.gradle file:

apply plugin: 'jacoco'  
apply plugin: 'java'  
jacoco {  
  toolVersion = "0.8.2"  
}  

jacocoTestReport {  
reports {  
  xml.enabled true  
  csv.enabled false  
  html.enabled true  
}  

afterEvaluate {  
  classDirectories = files(classDirectories.files.collect {  
     fileTree(dir: it, exclude: '**xxx/yyy/zzz/**')  
  })  
}  

task coverage { dependsOn 'jacocoTestReport' }  

check.dependsOn 'jacocoTestReport'  


我的sonar.gradle文件中的以下内容:


The following in my sonar.gradle file:

apply plugin: 'org.sonarqube'  

sonarqube {  
properties {  
  property "sonar.forceAnalysis", "true"  
  property "sonar.forceAuthentication", "true"  
  property "sonar.java.coveragePlugin", "jacoco"  
  property "sonar.login", ""  
  property "sonar.password", ""  
 }  
}  

subprojects {  
 sonarqube {  
  properties {  
     property "sonar.jacoco.reportPaths", 
 "$buildDir/reports/jacoco/allTests.exec"
     property "sonar.junit.reportsPath", "$buildDir/test-results/test"  
  }  
 }  
}  

task sonar { dependsOn 'sonarqube' }  


在我的build.gradle中:


In my build.gradle:

apply from: 'gradle/sonar.gradle'  
...  
apply plugin: 'java'  
...  
subprojects {  
  apply from: '../gradle/jacoco.gradle'   
  ...  
}  


最后从我的Jenkins文件中:


And finally from my Jenkins file:

step([$class: 'JacocoPublisher', changeBuildStatus: false, 
 exclusionPattern: '**/*Test*.class', inclusionPattern: 
 '**/*.class', minimumBranchCoverage: '80', sourcePattern: '**/src'])  

try {  
 dir(BUILD_DIR) {  
 sh './gradlew sonar'  
}  


但是xxx.yyy.zzz仍然在詹金斯的报道报告中生成!


But still the xxx.yyy.zzz Is generated in the coverage report in Jenkins!

推荐答案

终于成功了!关键是JacocoPuplisher.

Finally got it working! The key is the JacocoPuplisher.

step([$class: 'JacocoPublisher', changeBuildStatus: false, exclusionPattern: 
'**/xxx/yyy/zzz/**/*.class, **/*Test*.class', inclusionPattern: '**/*.class', 
minimumBranchCoverage: '80', sourcePattern: '**/src'])

这是让我与詹金斯一起工作的唯一方法.

This is the only way to I get it to work with Jenkins.

设置sonar.coverage.exclusion或使用上面的afterEvaluate东西无效.

Setting the sonar.coverage.exclusion or using the afterEvalueate stuff above has no effect.

这篇关于从詹金斯(Jenkins)的Jacoco报道中排除包裹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆