【问题标题】:go code coverage report in Jenkins with cobertura plugin使用 cobertura 插件在 Jenkins 中执行代码覆盖率报告
【发布时间】:2016-08-01 20:49:32
【问题描述】:

我已经在 J​​enkins 中安装了 cobertura 插件,并使用以下命令 #go test -cover -p 1 $PKGS | go-junit-report > report.xml 运行了单元测试。我可以看到 report.xml 是使用代码覆盖率创建的,但我在 Jenkins 控制台中看到以下错误。请告诉我们问题是什么以及如何解决。

/bin/sh -xe /tmp/hudson1811800402022775798.sh
[Cobertura] Publishing Cobertura coverage report...
FATAL: Unable to find coverage results
java.io.IOException: <workspace>/report.xml is not a cobertura coverage report, please check your report pattern
    at hudson.plugins.cobertura.CoberturaPublisher$ParseReportCallable.invoke(CoberturaPublisher.java:566)
    at hudson.plugins.cobertura.CoberturaPublisher$ParseReportCallable.invoke(CoberturaPublisher.java:536)
    at hudson.FilePath.act(FilePath.java:1018)
    at hudson.FilePath.act(FilePath.java:996)
    at hudson.plugins.cobertura.CoberturaPublisher.perform(CoberturaPublisher.java:343)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:720)
    at hudson.model.Build$BuildExecution.post2(Build.java:185)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:665)
    at hudson.model.Run.execute(Run.java:1766)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:410)
[Cobertura] No coverage results were found using the pattern '**/report.xml' relative to '<some directory>'.  Did you enter a pattern relative to the correct directory?  Did you generate the XML report(s) for Cobertura?
Build step 'Publish Cobertura Coverage Report' changed build result to FAILURE
Finished: FAILURE

【问题讨论】:

    标签: jenkins-plugins code-coverage cobertura


    【解决方案1】:

    我已按照以下步骤生成覆盖率报告(适用于 Go 语言)

    gocovxml

    使用以下命令安装 gocov xml

    $ go get github.com/axw/gocov/...
    $ go get github.com/AlekSi/gocov-xml
    

    如果你有多个包,执行 go test 命令

    gocov test $PKGS -p 1 | gocov-xml > report.xml
    

    在发布 cobertura 覆盖率报告中提供 report.xml(Jenkins 中的构建后操作)

    **/report.xml
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-24
      • 1970-01-01
      • 1970-01-01
      • 2013-02-15
      相关资源
      最近更新 更多