【问题标题】:jenkins jacoco sonar integrationjenkins jacoco 声纳集成
【发布时间】:2017-03-09 05:52:41
【问题描述】:

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

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

Jenkins中的Sonarqube配置(Works in localhost)如下

Sonarqube 服务器位于 localhost 和 9000 端口

我的 Jenkins Home 目录如下

工作空间根目录:${JENKINS_HOME}/workspace/${ITEM_FULLNAME}/

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

Maven 配置

全新安装

声纳

Sonar

雅可可

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 

谁能帮我更正我的配置

【问题讨论】:

    标签: jenkins jacoco


    【解决方案1】:

    有点晚了,但也许可以帮助别人。 首先,您不使用 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
    

    【讨论】:

      猜你喜欢
      • 2013-12-21
      • 2017-02-19
      • 2018-10-24
      • 2018-01-08
      • 2018-11-15
      • 2016-09-22
      • 2013-05-10
      • 2014-04-09
      • 1970-01-01
      相关资源
      最近更新 更多