Jenkins Jacoco: How to prepare separate Jacoco reports for each sub-project under main project

Viewed 158

My spring boot micorservice project consists of 2 sub-projects. Each sub-project is one service. When I build my main project via Jenkins, there are 2 jacoco reports built but they both are reports of the first sub-project.

The locations:

  1. /home/zzz/.jenkins/workspace/MainProject/SubProject_A/build/jacoco
  2. /home/zzz/.jenkins/workspace/MainProject/SubProject_B/build/jacoco

both contains two different test.exec files. One each for sub-projects.

The location /home/zzz/.jenkins/jobs/MainProject/builds/10/jacoco/execFiles contains 2 folders exec0 and exec1.

Each of the folders contains the above two test.exec file. But it looks like Jenkins is considering only the first (exec0's test.exec) exec file for generating the report. Due to this I am seeing the same report for both sub-projects.

How to have explicit Jacoco reports for each sub-project? Also is there a way to customize the title of the Jacoco report? Currently both the report title show as 'Jacoco - Overall Coverage Summary'

Below is the Jenkinsfile script

// For brevity ignore Git clone, compile stages
stage('Test IMS'){
            steps{
              
                    dir('InstituteManagement'){
                            script {
                                     try {
                                            sh './gradlew test'
                                        } finally {
                                            junit '**/build/test-results/test/*.xml' 
                                        }
                            }
                            jacoco(
                                execPattern: '**/build/jacoco/**.exec',
                                classPattern: '**/build/classes/java/main',
                                sourcePattern: '**/src',
                                inclusionPattern: 'com/instMgmt/**',
                            )
                    }
                     
                    
                    
            }
        }
        
        stage('Test TMS'){
            steps{
                    dir('TestManagementService'){
                       script {
                                try {
                                    sh './gradlew test'
                                } finally {
                                            junit '**/build/test-results/test/*.xml' 
                                        }
                        }
                        jacoco(
                            execPattern: '**/build/jacoco/**.exec',
                            classPattern: '**/build/classes/java/main',
                            sourcePattern: '**/src',
                            inclusionPattern: 'com/testMgmt/**',
                        )
                    }
            }
            
        }
0 Answers
Related