Jenkins UI is always taking preference to display the second code coverage

Hi ,
In my jenkins file i have written the code to display the code coverage for both java (using jacoco) and c++ (using bazel coverage -cobertura) .however the jenkins log displaying that both the reports are published correctly but in jenkins UI always it is displaying the 2nd one that means the first report always showing as empty.

could anyone guide me to fix it?

Hello @ananta123 and welcome to this community :wave:

Could you please share your Jenkinsfile so that we can see how you configured that?
Thanks.

Sure @poddingue
This is the stage in our pipeline

 stage('Analyze code coverage') {
            when { expression { env.codeCoverage == "true" }}
            steps { container(c) { script {
                usageLog(env.sourceCommit,"coverage","ciaas_bazel_coverage","ciaas","jenkins","ciaas","jenkins",true)
                analyzeCodeCoverage()
            }}}
            post { always { container(c) { script {
                usageLog(env.sourceCommit,"coverage","ciaas_bazel_coverage","ciaas","jenkins","ciaas","jenkins",false,currentBuild.currentResult=="FAILURE"?usageLogLabels:getCompiledFileInfo())
            }}}}
        }

and the analyzecoverage method is:

def analyzeCodeCoverage() {
    env.CURRENT_STAGE = env.STAGE_NAME
    boolean coverageFileFount = false;
    sh """
        ./infrastructure/ci/code_coverage '${env.SERVICE_NAME}'
    """
    if (findFiles(glob: "ci-testlogs/**/jacoco.xml").length > 0) {
        println("jacoco file found")
        publishCoverage adapters: [jacocoAdapter('ci-testlogs/**/jacoco.xml')]
        coverageFileFount = true;
    }
    if(fileExists(env.CODE_COVERAGE_FILE)) {
        println("coverage file found")
        def coverage_file = readFile(env.CODE_COVERAGE_FILE)
        if (coverage_file.size()) {
            cobertura(autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: env.CODE_COVERAGE_FILE,
                    conditionalCoverageTargets: '70, 0, 0', failNoReports: false, failUnhealthy: false, failUnstable: false,
                    lineCoverageTargets: '80, 0, 0', maxNumberOfBuilds: 0, methodCoverageTargets: '80, 0, 0', onlyStable: false,
                    sourceEncoding: 'ASCII', zoomCoverageChart: false)
        }
        coverageFileFount = true;
    }
    if (!coverageFileFount) {
        unstable("Code coverage file not found.")
    }
}

And as i mentioned jenkins log i can see both the reports are generated successfully but not displaying the 1st one.

1 Like

jenkins log displaying that both the reports are published correctly

What messages are shown in the log?

displaying the 2nd one that means the first report always showing as empty.

What is shown for the first report? Is there a coverage report link? Is the chart empty or not there? A little more details would help

1 Like

yes 1st report is always showing as empty.
message from log:
[Pipeline] echo 12:01:38 jacoco file found 12:01:38 [Pipeline] publishCoverage 12:01:38 Publishing Coverage report… 12:01:38 A total of 1 reports were found 12:01:38 Report coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Group coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Package coverage diff: 0.0%. Add to CoverageResult. 12:01:38 File coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Class coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Method coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Instruction coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Line coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Conditional coverage diff: 0.0%. Add to CoverageResult. 12:01:38 [Coverage] Computing coverage delta report 12:01:38 [Coverage] Reference build recorder is not configured 12:01:38 [Coverage] → No reference build defined, falling back to previous build 12:01:38 [Coverage] → Found reference result ‘io.jenkins.plugins.coverage.CoverageAction@22484e52’ 12:01:38 [Checks API] No suitable checks publisher found. 12:01:38

[Pipeline] fileExists 12:01:38 [Pipeline] echo 12:01:38 coverage file found 12:01:38 [Pipeline] readFile 12:01:38 [Pipeline] cobertura 12:01:38 [Cobertura] Publishing Cobertura coverage report… 12:01:38 12:01:40 [Cobertura] Publishing Cobertura coverage results… 12:01:40 12:01:40 [Cobertura] Cobertura coverage report found.

yes 2nd report is always empty…it is only publishing if you see below log.

[Pipeline] echo 12:01:38 jacoco file found 12:01:38 [Pipeline] publishCoverage 12:01:38 Publishing Coverage report… 12:01:38 A total of 1 reports were found 12:01:38 Report coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Group coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Package coverage diff: 0.0%. Add to CoverageResult. 12:01:38 File coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Class coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Method coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Instruction coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Line coverage diff: 0.0%. Add to CoverageResult. 12:01:38 Conditional coverage diff: 0.0%. Add to CoverageResult. 12:01:38 [Coverage] Computing coverage delta report 12:01:38 [Coverage] Reference build recorder is not configured 12:01:38 [Coverage] → No reference build defined, falling back to previous build 12:01:38 [Coverage] → Found reference result ‘io.jenkins.plugins.coverage.CoverageAction@22484e52’ 12:01:38 [Checks API] No suitable checks publisher found. 12:01:38 [Pipeline] fileExists 12:01:38

[Pipeline] echo 12:01:38 coverage file found 12:01:38 [Pipeline] readFile 12:01:38 [Pipeline] cobertura 12:01:38 [Cobertura] Publishing Cobertura coverage report… 12:01:38 12:01:40 [Cobertura] Publishing Cobertura coverage results… 12:01:40 12:01:40 [Cobertura] Cobertura coverage report found.

In this log 1st report is for java which is getting overridden so i am only seeing the 2nd one in the jenkins UI

Can you please write the log messages in a code block?

Can you please post a screenshot? I have no idea what you mean with empty. Also show the link URLs that you did click where an empty page opens.

BTW: you are using 2 different coverage reporters (code-coverage plugin and cobertura plugin) so they have basically two different UIs.

Yes i am using 2 reports and both i am publishing from jenkins …so in jenkins UI

and in jenkins UI,i can only see the 2nd report that is java one and cobertura one is empty.

1 Like

1 Like

Ok, then it makes sense to see why cobertura is not showing a result. Can you try just with cobertura and without publishCoverage? Does that help?

Which URL is shown when you open the cobertura report (is it jenkins/jobs/jobname/buildnumber/cobertura)? When you open the developer console of your browser, are there errors? Or are there errors in Jenkins Log (not in the build log).

1 Like

Hi,

I tried only cobertura and it is displaying correctly .
yes it is under jenkins/jobs/jobname/buildnumber/cobertura)
But my question is i am publishing 2 times different different report but why it is overriding the 1st one?

What is shown in the UI for the URL jenkins/jobs/jobname/buildnumber/cobertura when both plugins are active?

it is empty.

From my understanding the view is not empty :slight_smile: but I think that I understand what you mean. BTW: You still need to provide more details and answer the questions, otherwise we can’t help.

The screenshot you are showing is from the code coverage plugin which provide links to the results of the form “jenkins/jobs/jobname/buildnumber/coverage” and not “jenkins/jobs/jobname/buildnumber/cobertura” . So you are probably hitting Code Coverage Report is overwritten when calling publishCoverage twice · Issue #236 · jenkinsci/code-coverage-api-plugin · GitHub

Hi,

In my application i have 2 modules c++,java.you can see the code in the very first post .we are publishing the coverage for both module.

In the log we didn’t see any error but on the Jenkins UI the first is always displaying as empty and 2nd report has proper data.

C++ is using bazel to publish the report.since it is not working now i am currently only displaying Java report as mentioned the code .

Is there anything i have to do to display both the coverages?

Regards,
Ananta

Since this feature request is not yet implemented, you need to wait until someone finds the time to provide a PR.

As a workaround you can use the cobertura plugin for one report and the coverage plugin for the other.

Do you have any example ?Could you please provide one ?because we are currently using both the plugins in our jenkins

But while displaying the report it is always using coverage plugin.
Do i need to modify the pipeline code or add any dependency?

You are already using both plugins in your pipeline. Just call one with the cobertura.xml and the other one with the jacoco.xml.

we are already doing that if you see my earlier code but it is not working.
BTW Could you please give me the ticket to track - when the coverage report display both reports.