Jenkins Cobertura插件无法找到coverage.xml文件。

9
我在Jenkins 1.502中使用jenkins-cobertura插件版本1.9.3,拥有一个多模块的Maven项目。我的cobertura.xml文件是在web-app模块中生成的,在Jenkins中浏览我的项目的工作空间时可以看到它。我尝试了多种不同的方法来设置后构建操作中的路径,以指向cobertura.xml文件,但插件仍然说找不到它。我得到了以下错误信息:“[Cobertura] No coverage results were found using the pattern 'app/web-app/target/site/cobertura/cobertura.xml' relative to 'C:\Jenkins\jobs\Dev - appName - trunk\workspace'”。我的web应用程序的maven pom.xml文件在pom.xml的“section”中如下设置了cobertura:
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <formats>                       
                    <format>xml</format>
                    <format>html</format>
                </formats>
                <instrumentation>
                    <excludes>
                        <exclude>**/*Test.class</exclude>
                        <exclude>**/Mock*.class</exclude>
                    </excludes>
                </instrumentation>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>cobertura</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

在 Jenkins 中,我的 Maven 构建选项如下:

-Pqa clean cobertura:cobertura install

编辑 我找到了我的问题,我将文件命名为“cobertura.xml”,而不是“coverage.xml”,或者最好的方式是选择所有这些文件:

**/target/site/cobertura/*.xml

2个回答

8
将以下行添加到您的应用程序目标(Jenkins中应用程序的配置部分)中:
cobertura:cobertura -Dcobertura.report.format=xml

pom.xml 变更:

<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <formats>
                    <format>html</format>
                    <format>xml</format>
                </formats>
            </configuration>
        </plugin>
    </plugins>
</reporting>

2
Cobertura的输出可以是XML或HTML格式。
<formats>                       
   <format>xml</format>
 </formats>

确保结果(coverage.xml)可在此目录中获得, $JENKINS_HOME/workspace/..job../app/web-app/target/site/cobertura/coverage.xml 文件。

或者检查Cobertura报告的目标目录。

或者获取一个样本文件并尝试将其放在作业目录下,看看它是如何工作的...


1
额外的HTML格式不会使Jenkins-Cobertura插件出现问题,至少对我来说不会。 - doug78

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接