2

I have a Jenkins multi branch pipeline.

stage('Run tests') {
            steps {
                sh 'npm run-script test -- --coverage --testResultsProcessor=jest-junit --outputFile=test-results.xml'
            }
            post {
                always {
                    junit 'junit.xml'
                    cobertura coberturaReportFile: '**/coverage/cobertura-coverage.xml'
                    recordCoverage(tools: [[parser: 'COBERTURA']], id: 'cobertura', name: 'Cobertura Coverage', sourceDirectories: [[path: '**/src']])
                }
            }
        }

it working fine and generate report for me, but I want to see the Coverage in the list of branch. How can I do it?

enter image description here

Yura Bysaha
  • 721
  • 6
  • 17

1 Answers1

1

I ran into a similar problems with JaCoCo. What I found was that the builds would not fail, even if the recordCoverage plugin failed. In reviewing the console output of the build, I discovered the following:

[JaCoCo] Using default pattern: '**/jacoco.xml' since user defined pattern is not set
...
[JaCoCo] [-ERROR-] No files found for pattern '**/jacoco.xml' Configuration Error?

I did a build locally and saw that JaCoCo wrote its output to build/reports/jacoco/test/jacocoTestReport.xml. I couldn't find anything in the plugin project's README that talked about how to specify a different location for the input files (the README does talk about specifying a different location for the source code files). After spelunking through the plugin's source code, I finally found an example of how to specify a different location using the pattern property as follows:

recordCoverage(
  tools: [[parser: 'JACOCO', pattern: '**/jacoco/test/jacocoTestReport.xml']],

After making that change and doing another build, I was able to see a link in the Coverage column on the list of branches page that you reference in your question. Clicking on that link brought me to the detailed coverage information. I hope something similar resolves your problem.

PRS
  • 11
  • 1