首页 > 解决方案 > Jenkins Pipeline - Codeception 测试 publishHTML - 没有 HTML 显示

问题描述

我有一个 Jenkins 管道,它构建了一个 docker 实例来启动一个 Symfony 项目,效果很好。我们使用 codeception 进行测试,我想将其添加到管道中,并在 Jenkins 中显示每个构建的代码覆盖率。

管道成功运行,测试通过并生成 HTML,publishHTML 步骤似乎成功,但 Jenkins UI 中没有显示任何内容。(我什至不确定在哪里看,因为它只是在文档中说“在仪表板中”)。

管道的相关部分:

    stage('Test') {
      steps {
        ansiColor('xterm') {
            sh 'ssh jenkins@10.90.0.211 "sudo docker exec broccoli_app_1 ./vendor/bin/codecept run unit --env edge --coverage-html"'  
        }
      }
    }
  }
  post {
      always {
          echo 'Running post build script to publish report'
          publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: 'broccoli/tests/_output/coverage/', reportFiles: 'index.html', reportName: "HTML Report", reportTitles: "Coverage Report"])
      }
  }

在控制台中,它返回似乎是非失败消息:

[Pipeline] echo
Running post build script to publish report
[Pipeline] publishHTML
[htmlpublisher] Archiving HTML reports...
[htmlpublisher] Archiving at BUILD level /var/lib/jenkins/workspace/broccoli2stage/broccoli/tests/_output/coverage to /var/lib/jenkins/jobs/broccoli2stage/builds/56/htmlreports/HTML_20Report
[Pipeline] }

我还缺少其他配置吗?

标签: jenkinsjenkins-pipelinecodeception

解决方案


最终让这个工作。我认为我的解决方案不一定适用于许多情况。

你可以在这一行看到,我们登录到一个单独的服务器来运行测试:

 sh 'ssh jenkins@10.90.0.211 "sudo docker exec broccoli_app_1 ./vendor/bin/codecept run unit --env edge --coverage-html"'  

所以 publishHTML 无权访问代码运行结果。事实证明,我们不需要为这个构建设置这样做,所以只需在本地运行它就可以让它工作。

 sh 'sudo docker exec broccoli_app_1 codecept run unit --env edge --coverage-html'

推荐阅读