首页 文章

jenkins jacoco声纳整合

提问于
浏览
0

我在Jenkins中使用声纳配置Jacoco时遇到了问题 .

目前我正在创建一个Jenkins工作,我的目的是在将代码更改推送到git Hub后进行自动构建 . 之后,我需要接受代码覆盖率报告,并使用带声纳的Jacoco实现 .

Jenkins中的

Sonarqube配置(在localhost中工作)如下所示

Sonarqube服务器位于localhost和端口9000

我的Jenkins Home目录如下

工作空间Root Dir:$ / workspace / $ /

然后我创建了一个名为Test123的新作业 . 在Build选项中,我按如下方式配置了Maven,Sonar,Jacoco

Maven配置

干净安装

声纳

Sonar

Jacoco

Jacoco

我的Pom.xml

<build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.15</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>${maven.test.skip}</skip>
                            <argLine>${argLine}</argLine>
                            <excludes>
                                <exclude>**/*IntegrationTest.java</exclude>
                            </excludes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>${skipITs}</skip>
                            <argLine>${argLine}</argLine>
                            <includes>
                                <include>**/*IntegrationTest.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.4.201502262128</version>
                <configuration>
                    <skip>${maven.test.skip}</skip>
                    <destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
                    <dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
                    <output>file</output>
                    <append>true</append>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>

    </build>

构建结果如下

[JaCoCo plugin] Collecting JaCoCo coverage data...
[JaCoCo plugin] **/*.exec;**/*classes;**/src; locations are configured
[JaCoCo plugin] Number of found exec files for pattern **/*.exec: 1
[JaCoCo plugin] Saving matched execfiles:  C:\Users\pxp167\.jenkins\workspace\Test123\target\coverage-reports\jacoco-unit.exec
[JaCoCo plugin] Saving matched class directories for class-pattern: **/*classes:  C:\Users\pxp167\.jenkins\workspace\Test123\target\classes C:\Users\pxp167\.jenkins\workspace\Test123\target\test-classes
[JaCoCo plugin] Saving matched source directories for source-pattern: **/src:  C:\Users\pxp167\.jenkins\workspace\Test123\src
[JaCoCo plugin] Loading inclusions files..
[JaCoCo plugin] inclusions: [**/*.class]
[JaCoCo plugin] exclusions: [**/*Test*]
[JaCoCo plugin] Thresholds: JacocoHealthReportThresholds [minClass=0, maxClass=50, minMethod=0, maxMethod=50, minLine=0, maxLine=50, minBranch=0, maxBranch=50, minInstruction=0, maxInstruction=50, minComplexity=0, maxComplexity=50]
[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
Build step 'Record JaCoCo coverage report' changed build result to UNSTABLE
Finished: UNSTABLE

任何人都可以帮我纠正我的配置

1 回答

  • 0

    有点迟,但也许帮助别人 . 首先,你不使用Sonar的测试覆盖率,而是使用“Jenkins JaCoCo插件” . 单击JaCoCo旁边的Post Build Actions中的问号 .

    如果您的问题是0测试覆盖率,可能是没有找到文件 . 检查类和源配置,您应该在找到类的日志中找到一些内容:

    [JaCoCo plugin] Number of found exec files for pattern **/**.exec: 3
    [JaCoCo plugin] Saving matched execfiles:  /srv/jenkins/workspace/eature_ContinousIntegration--api/build/jacoco/test.exec /srv/jenkins/workspace/-batch/build/jacoco/test.exec /srv/jenkins/workspace/-domain/build/jacoco/test.exec
    [JaCoCo plugin] Saving matched class directories for class-pattern: **/classes: 
    [JaCoCo plugin]  - /srv/jenkins/workspace/eature_ContinousIntegration-api/build/classes 8 files
    [JaCoCo plugin]  - /srv/jenkins/workspace/-api/build/reports/tests/test/classes 0 files
    

相关问题