需要帮助来使用 JenkinsFile 中的 BUILD_LOG_REGEX 格式化匹配行

问题描述 投票:0回答:1

我有一个 JenkinsFile,我在其中使用 emailext 发送邮件以获取自动化结果

def subject = "Jenkins Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}"
def color = currentBuild.currentResult == 'FAILURE' ? 'red' : 'green'

    emailext (
    mimeType: 'text/html',
    attachLog: true,
    subject: subject,
    body: 
    """
    <h3><font color='${color}'>${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} </h3></font><br> More info at: ${env.BUILD_URL}<br><br>
    Total test case:  \${TEST_COUNTS,var="total"} <br>
    Pass:               \${TEST_COUNTS,var="pass"}  <br>
    Fail:               \${TEST_COUNTS,var="fail"}  <br>
    <br>
    ${htmlTable}
    <br>
    \${BUILD_LOG_REGEX, regex="^.*Check out job at", showTruncatedLines="false",substText=" Access the test recording here:"}<br><br>
    <p>Click the link below to view the report:</p><a href="${env.BUILD_URL}/QmateReport">View Report</a>
    """,
    to: '[email protected]'
)       

对于此行 - ${BUILD_LOG_REGEX, regex="^.*Check out job at", showTruncatedLines="false",substText=" 在此处访问测试记录:"}

我收到了多个匹配项,并且全部以未格式化的方式排列在一行中。

有没有办法在 NextLine 中获取电子邮件中那些匹配的记录

这是我们在电子邮件中收到的结果。

我想在 NextLine 中看到这个

在此处访问录音:
在这里访问录音:

我尝试使用以下两点

  1. 在 substText 中使用 /n
\${BUILD_LOG_REGEX, regex="^.*Check out job at", showTruncatedLines="false",substText=" Access the test recording here: \n"}<br><be> 
  1. 使用实际的换行符:而不是 ,尝试在字符串中使用实际的换行符。您可以通过在冒号后按 Enter 并在下一行继续该字符串来实现此目的。例如:
\${BUILD_LOG_REGEX, regex="^.*Check out job at", showTruncatedLines="false",substText=" Access the test recording here: 
"}

但是没有任何效果,请帮忙。

jenkins-pipeline jenkins-plugins jenkins-groovy email-ext jenkins-email-ext
1个回答
0
投票

问题陈述

2.0-beta
版本开始,
BUILD_LOG_REGEX
宏始终支持默认为 true 的 addNewline 属性。它应该已经在每场比赛的末尾放置一个新行字符。

但是,如果这不起作用,可以尝试使用

matchedLineHtmlStyle
属性,该属性允许您为每个表达式匹配提供样式。例如,以下
matchedLineHtmlStyle
值会在匹配之间产生干净的新行分隔:

emailext (
    mimeType: 'text/html',
    attachLog: true,
    subject: subject,
    body: 
    """
    <h3><font color='${color}'>${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} </h3></font><br> More info at: ${env.BUILD_URL}<br><br>
    Total test case:  \${TEST_COUNTS,var="total"} <br>
    Pass:               \${TEST_COUNTS,var="pass"}  <br>
    Fail:               \${TEST_COUNTS,var="fail"}  <br>
    <br>
    ${htmlTable}
    <br>
    \${BUILD_LOG_REGEX, regex="^.*Check out job at", showTruncatedLines="false", matchedLineHtmlStyle="margin-bottom: 1em; display: inline-block;", addNewline="true", substText=" Access the test recording here:"}<br><br>
    <p>Click the link below to view the report:</p><a href="${env.BUILD_URL}/QmateReport">View Report</a>
    """,
    to: '[email protected]'
)       
© www.soinside.com 2019 - 2024. All rights reserved.