目前我正在创建一个Jenkins的工作,我的意图是在我将代码更改推送到git Hub后自动构建。之后,我需要获取代码覆盖率报告,并使用带有声纳的Jacoco实现。
Sonarqube服务器localhost和端口为9000
工作空间根目录:${JENKINS_HOME}/workspace/${ITEM_FULLNAME}/
然后我创建了一个名为Test123的新Job。在Build选项中,我配置了Maven、Sonar、Jacoco,如下所示
干净安装
声纳
雅各科
<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
有点晚,但可能会帮助其他人。首先,您不使用Sonar的测试覆盖,而是使用“JenkinsJaCoCo插件”。单击JaCoCo旁边的构建后操作中的问号。
如果您的问题是关于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