When the coverage is low and the pipeline fails, it would be useful to look at the code coverage report and find what parts are not yet covered with tests. We could run Gradle locally and generate the coverage report; however, it is more convenient if Jenkins shows the report for us.
In order to publish the code coverage report in Jenkins, we need the following stage definition:
stage("Code coverage") { steps { sh "./gradlew jacocoTestReport" publishHTML (target: [ reportDir: 'build/reports/jacoco/test/html', reportFiles: 'index.html', reportName: "JaCoCo Report" ]) sh "./gradlew jacocoTestCoverageVerification" }}
This stage copies the generated JaCoCo report to the Jenkins output. When we run the build ...