【问题标题】:Jenkins send email with part of log line詹金斯发送带有部分日志行的电子邮件
【发布时间】:2019-05-08 05:12:06
【问题描述】:

我在 Jenkins 中有 10 个测试用例的 SOAPUI 项目。我设置 Jenkins 向我发送包含控制台输出(日志)信息的电子邮件。我已将电子邮件通知内容设置为 HTML (text/html)。

我在 Jenkins 中有这个登录控制台输出:

07:25:05,957 INFO  [SoapUITestCaseRunner] Running SoapUI testcase [Login with username and password]
07:25:05,957 INFO  [SoapUITestCaseRunner] running step [Clear access token]
07:25:05,957 INFO  [log] Environment URL: url.test.environment
07:25:05,958 INFO  [SoapUITestCaseRunner] running step [Retrieve accessToken]
07:25:05,959 DEBUG [HttpClientSupport$SoapUIHttpClient] Stale connection check
07:25:05,960 DEBUG [HttpClientSupport$SoapUIHttpClient] Attempt 1 to execute request
07:25:05,960 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Sending request: POST /api/v2/path HTTP/1.1
07:25:06,010 DEBUG [SoapUIMultiThreadedHttpConnectionManager$SoapUIDefaultClientConnection] Receiving response: HTTP/1.1 200 
07:25:06,011 DEBUG [HttpClientSupport$SoapUIHttpClient] Connection can be kept alive indefinitely
07:25:06,017 INFO  [SoapUITestCaseRunner] Assertion [JsonPath Existence Match] has status VALID
07:25:06,017 INFO  [SoapUITestCaseRunner] Assertion [Valid HTTP Status Codes] has status VALID
07:25:06,017 INFO  [SoapUITestCaseRunner] Assertion [JsonPath Existence Match 1] has status VALID
07:25:06,017 INFO  [SoapUITestCaseRunner] Assertion [JsonPath Existence Match 2] has status VALID
07:25:06,017 INFO  [SoapUITestCaseRunner] running step [Pass accessToken]
07:25:06,019 INFO  [SoapUITestCaseRunner] Finished running SoapUI testcase [Login with username and password], time taken: 51ms, status: FINISHED

我已将 Jenkins 设置为仅使用日志中的这一行发送电子邮件:

07:25:06,019 INFO  [SoapUITestCaseRunner] Finished running SoapUI testcase [Login with username and password], time taken: 51ms, status: FINISHED

为此,我使用此正则表达式来查找该行:

<pre>${BUILD_LOG_REGEX, regex="Finished running SoapUI testcase \\[Login with username and password\\]", showTruncatedLines=false}</pre>

但我想在电子邮件通知中只包含该行的一部分,如下所示:

"Login with username and password: FINISHED"

"Login with username and password: FAILED"

有没有办法只用那一行的一部分发送电子邮件?

【问题讨论】:

  • 您可以尝试使用正则表达式的 replaceAll:".+\\[(Login with username and password)\\].*:\\s*(\\w+)$", "$1: $2"

标签: regex jenkins jenkins-plugins jenkins-email-ext


【解决方案1】:

感谢 Aaron,我找到了解决方案。

现在我使用这个正则表达式:

<b>Login with username and password: </b> <font color="green">${BUILD_LOG_REGEX, regex=".*Finished running SoapUI testcase \\[Login with username and password\\].*status: FINISHED", showTruncatedLines=false, substText="SUCCESS"}</font>
<font color="red">${BUILD_LOG_REGEX, regex=".*Finished running SoapUI testcase \\[Login with username and password\\].*status: FAILED", showTruncatedLines=false, substText="FAILED"}</font>

电子邮件通知现在如下所示:

使用用户名和密码登录:成功


或者这个:

使用用户名和密码登录:FAILED


“SUCCESS”文本为绿色,“FAILED”文本为红色

【讨论】:

    【解决方案2】:

    您似乎可以使用substr 参数来定义替换模式:

    <pre>${BUILD_LOG_REGEX, regex="Finished running SoapUI testcase \\[Login with username and password\\].*status: ([A-Z]+)", showTruncatedLines=false, substr="Login with username and password : \\1"}</pre>
    

    这将仅匹配示例中的最后一行等行,请在替换模式中引用的第一个捕获组中选择成功/失败状态。

    【讨论】:

    • substr 对我不起作用,但感谢您我找到了解决方案。
    • @MarekMasek 很高兴听到这个消息!
    • 实际参数名称是substText --注意:正则表达式也必须在捕获组之外匹配。如果您不指定捕获组之外的任何内容,则只会替换捕获组本身。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多