How to get Jenkins to exclude entire folders from code coverage?

后端 未结 3 846
悲哀的现实
悲哀的现实 2021-01-12 10:18

I\'m trying to figure out how to exclude a list of folders from the code coverage report generated by jacoco, which is launched by Jenkins.

It seems possible to excl

3条回答
  •  佛祖请我去吃肉
    2021-01-12 10:44

    If you are using pipelines and Jenkinsfile you can use the following as an example of the settings (assumes gradle):

     stage("Check code quality and coverage") {
              steps{
               sh "./gradlew jacocoTestReport sonarqube -x check"               
               step( [$class: 'JacocoPublisher',
                      exclusionPattern: '**/*Exception*,**/*Configuration*,**/ApiApplication*,**/*Test*'] )
              }
        }
    

    Of note here is the exclusionPattern is comma separated and NO SPACES between the multiple exclusion patterns.

    The easiest way to see the full list of potential settings is to look at the code:

    https://github.com/jenkinsci/jacoco-plugin/blob/master/src/main/java/hudson/plugins/jacoco/JacocoPublisher.java

    And check out the @DataBoundSetter's

    public JacocoPublisher() {
        this.execPattern = "**/**.exec";
        this.classPattern = "**/classes";
        this.sourcePattern = "**/src/main/java";
        this.inclusionPattern = "";
        this.exclusionPattern = "";
        this.skipCopyOfSrcFiles = false;
        this.minimumInstructionCoverage = "0";
        this.minimumBranchCoverage = "0";
        this.minimumComplexityCoverage = "0";
        this.minimumLineCoverage = "0";
        this.minimumMethodCoverage = "0";
        this.minimumClassCoverage = "0";
        this.maximumInstructionCoverage = "0";
        this.maximumBranchCoverage = "0";
        this.maximumComplexityCoverage = "0";
        this.maximumLineCoverage = "0";
        this.maximumMethodCoverage = "0";
        this.maximumClassCoverage = "0";
        this.changeBuildStatus = false;
        this.deltaInstructionCoverage = "0";
        this.deltaBranchCoverage = "0";
        this.deltaComplexityCoverage = "0";
        this.deltaLineCoverage = "0";
        this.deltaMethodCoverage = "0";
        this.deltaClassCoverage = "0";
        this.buildOverBuild = false;
    }
    

提交回复
热议问题