首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jenkins jacoco声纳集成

jenkins jacoco声纳集成
EN

Stack Overflow用户
提问于 2017-03-09 13:52:42
回答 1查看 1.1K关注 0票数 0

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

目前,我正在创建一个Jenkins工作,我的意图是一旦我将代码更改推送到git Hub中,就会进行自动构建。之后,我需要采取代码复盖率报告,并使用Jacoco与声纳实现。

Jenkins中的Sonarqube配置(适用于localhost)如下所示

Sonarqube服务器位于本地主机,端口为9000

我的Jenkins Home目录如下所示

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

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

Maven配置

全新安装

声纳

Sonar

雅可可

Jacoco

我的Pom.xml

代码语言:javascript
复制
<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>

构建结果如下

代码语言:javascript
复制
[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 

有没有人可以帮我纠正我的配置

EN

回答 1

Stack Overflow用户

发布于 2018-01-11 21:13:49

有点晚了,但可能会帮助其他人。首先,您根本没有使用Sonar的测试覆盖率,而是使用了"Jenkins JaCoCo插件“。单击JaCoCo旁边的构建后操作中的问号。

如果你的问题是关于0测试覆盖率,可能是找不到任何文件。检查类和源代码配置,您应该在日志中有找到类的内容:

代码语言:javascript
复制
[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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42687741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档