Покрытие кода Jacoco показывает 0% покрытия на Jenkins

Я прочитал большинство ответов на похожие вопросы, но ни один из них не подходит для ответа на мой вопрос.

Мой профиль в файле pom выглядит так:

            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.7.201606060606</version>
                    <executions>
                        <!-- Prepares the property pointing to the JaCoCo runtime agent which 
                            is passed as VM argument when Maven the Surefire plugin is executed. -->
                        <execution>
                            <id>pre-unit-test</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                            <configuration>
                                <!-- Sets the path to the file which contains the execution data. -->
                                <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                                <!-- Sets the name of the property containing the settings for JaCoCo 
                                    runtime agent. -->
                                <propertyName>surefireArgLine</propertyName>
                            </configuration>
                        </execution>
                        <!-- Ensures that the code coverage report for unit tests is created 
                            after unit tests have been run. -->
                        <execution>
                            <id>post-unit-test</id>
                            <phase>test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <!-- Sets the path to the file which contains the execution data. -->
                                <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                                <!-- Sets the output directory for the code coverage report. -->
                                <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                    <executions>
                        <execution>
                            <id>surefire-unit-tests</id>
                            <phase>test</phase>
                            <goals>
                                <goal>test</goal>
                            </goals>
                            <configuration>
                                <!-- Sets the VM argument line used when unit tests are run. -->
                                <argLine>${surefireArgLine}</argLine>
                                <!-- Skips unit tests if the value of skip.unit.tests property is 
                                    true -->
                                <skipTests>${skip.unit.tests}</skipTests>
                                <!-- Excludes integration tests when unit tests are run. -->
                                <skip>false</skip>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.19.1</version>
                    <executions>
                        <!-- Ensures that both integration-test and verify goals of the Failsafe 
                            Maven plugin are executed. -->
                        <execution>
                            <id>integration-tests</id>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                            <configuration>
                                <!-- Sets the VM argument line used when integration tests are run. -->
                                <argLine>${failsafeArgLine}</argLine>
                                <!-- Skips integration tests if the value of skip.integration.tests 
                                    property is true -->
                                <skipTests>${skip.integration.tests}</skipTests>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>

Когда я запускаю свою работу Дженкинса с целью maven clean install -P test-coverage

Я вижу это в своем журнале Дженкинса:

`[JaCoCo plugin] Collecting JaCoCo coverage data...
[JaCoCo plugin] **/target/coverage-reports/jacoco-ut.exec;**/target/classes;**/src/main/java; locations are configured
[JaCoCo plugin] Number of found exec files for pattern **/target/coverage-reports/jacoco-ut.exec: 0
[JaCoCo plugin] Saving matched execfiles:  
[JaCoCo plugin] Saving matched class directories for class-pattern: **/target/classes: 
[JaCoCo plugin] Saving matched source directories for source-pattern: **/src/main/java: 
[JaCoCo plugin] Loading inclusions files..
[JaCoCo plugin] inclusions: []
[JaCoCo plugin] exclusions: []
[JaCoCo plugin] Thresholds: JacocoHealthReportThresholds [minClass=0, maxClass=0, minMethod=0, maxMethod=0, minLine=0, maxLine=0, minBranch=0, maxBranch=0, minInstruction=0, maxInstruction=0, minComplexity=0, maxComplexity=0]
[JaCoCo plugin] Publishing the results..
[JaCoCo plugin] Loading packages..
[JaCoCo plugin] Done.
[JaCoCo plugin] Overall coverage: class: 0, method: 0, line: 0, branch: 0, instruction: 0`

Вот как выглядит моя конфигурация Jenkins для Jacoco:

введите здесь описание изображения


person ASR    schedule 16.01.2017    source источник
comment
Обратите внимание на строку Number of found exec files for pattern **/target/coverage-reports/jacoco-ut.exec: 0 в вашем журнале Jenkins — вам нужно понять, почему такого файла нет, что требует просмотра журнала сборки намного выше этой строки.   -  person Godin    schedule 16.01.2017
comment
@Godin Только что добился успеха. На самом деле каталог сборки отличался от рабочего пространства Дженкинса.   -  person ASR    schedule 16.01.2017
comment
Также изменено местоположение исполняемого файла на **/jacoco.exec, лучше следуйте тому, что предлагает плагин.   -  person ASR    schedule 16.01.2017
comment
Затем, чтобы быть хорошим гражданином StackOverflow, пожалуйста, либо удалите свой вопрос, либо опубликуйте правильный ответ на него - meta.stackexchange.com/questions/17845/   -  person Godin    schedule 16.01.2017
comment
Это может случиться и с другими, поэтому ответ на него будет полезен для других.   -  person ASR    schedule 16.01.2017


Ответы (3)


В моем случае я использовал jacocoant 0.6, а плагин jaCoCo для jenkins был 2.2.0. Со страницы плагина jaCoCo на github:

Версия 2.0.0 и выше требует использования JaCoCo 0.7.5 или новее, если ваши проекты все еще используют JaCoCo 0.7.4, плагин больше не будет отображать цифры покрытия кода! В этом случае используйте версию 1.0.19, пока вы не сможете обновить jacoco в своей кодовой базе. https://github.com/jenkinsci/jacoco-plugin

person Roberto    schedule 04.05.2017

В моем случае не удалось получить файл exec.

Это потому, что мой каталог сборки отличался от рабочего пространства Jenkins WORKSPACE. Когда я изменил каталог сборки на WORKSPACE, произошло волшебство.

person ASR    schedule 16.01.2017
comment
привет, не могли бы вы указать изменения, которые вы сделали. Я получаю ту же ошибку - person Soubhik Banerjee; 09.04.2020
comment
@SoubhikBanerjee, я думаю, что мое рабочее пространство Jenkins отличалось от $WORKSPACE по умолчанию. вы можете попробовать указать абсолютный путь к файлу .exec. - person ASR; 09.04.2020

В моем случае плагин Jacoco 1.0.19, но я использую Jacoco-maven-plugin 0.7.9, который несовместим.

Итак, после смены Jacoco-maven-plugin на 0.7.4.x. Я получаю правильное освещение о Дженкинсе

person Surasin Tancharoen    schedule 04.12.2017