首页 > 解决方案 > 将 HTML 输出嵌入 Jenkins 仪表板

问题描述

我是詹金斯的新手,我正在努力解决一个问题。我想将 HTML 输出嵌入到 jenkins 仪表板中。我尝试了几种方法,但都没有成功。这是我获取 html 输出的管道阶段的代码片段:

    stage('Test score Calculations'){
      steps{
        script{
          ansiColor('xterm') {
            def buildSummaryFragments = ["""<table border="1px"><thead><tr>
                <th>Module</th>
                <th>Lint</th>
                <th>Unit Test</th>
                <th>Behave Test</th>
                <th>Coverage</th>
            </tr></thead><tbody>"""]

            def ms_file = readFile "mod_ms.txt"
            def files = ms_file.split("\n")
            for (int msCount = 0; msCount< files.size();msCount++) {
              println "preparing summary for ${files[msCount]}"
              buildSummaryFragments += [createBuildSummary("${files[msCount]}")]
            }
            buildSummaryFragments += ["</tbody></table>"]
            println(buildSummaryFragments)

简而言之,这里发生了什么:

  1. 该脚本正在从文本文件中读取应用程序名称
  2. 对于每个名称,它在 createBuildSummary() 函数中对这些应用程序进行一些测试,其输出以 html 格式出现并存储在 buildSummaryFragments

buildSummaryFragments 的输出如下所示:

16:34:57  [<table border="1px"><thead><tr>
16:34:57                  <th>Module</th>
16:34:57                  <th>Lint</th>
16:34:57                  <th>Unit Test</th>
16:34:57                  <th>Behave Test</th>
16:34:57                  <th>Coverage</th>
16:34:57              </tr></thead><tbody>, <tr>
16:34:57        <td style="background-color:#d9eedb;">cloudx_demo_service</td>
16:34:57        <td style="background-color:#d9eedb;">9.23/10 (previous run: 9.23/10, +0.00)</td>
16:34:57        <td style="background-color:#d9eedb;">nosetests: 1/1 passed: 100% success
16:34:57  </td>
16:34:57        <td style="background-color:#d9eedb;"><Element 'testsuite' at 0x7ff60219f410>
16:34:57  service.Heart beat for the demo App: 1/1 passed: 100% success
16:34:57  </td>
16:34:57        <td style="background-color:#d9eedb;">100%
16:34:57  </td>
16:34:57    </tr>, </tbody></table>]

我想将此 html 结果附加到构建的仪表板中。在仪表板中,它会给我一个像这样的表格: 在此处输入图像描述

我想将此 buildSummaryFragments 存储在 html 文件中。您能否建议如何将其写入文件 - 使用以下两种方式:

  1. 尝试使用 groovy 写入 html(我在执行此操作时遇到了两个问题 - 一个具有写入权限,第二个是变量类型为 arraylist 而不是字符串)
  2. 我尝试在 shell 中做一个回声。但由于大量特殊字符无法正常工作。请建议使用什么过滤器。

这个你能帮我吗。提前致谢

标签: htmlshellunixjenkinsgroovy

解决方案


推荐阅读