詹金斯通过部分日志行发送电子邮件

时间:2018-12-06 13:28:15

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

我在Jenkins中有SOAPUI项目,其中包含10个测试用例。我设置了Jenkins,向我发送包含控制台输出(日志)信息的电子邮件。我已将电子邮件通知内容设置为HTML(文本/ 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"

有什么方法可以仅发送该行的一部分来发送电子邮件吗?

2 个答案:

答案 0 :(得分:2)

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

现在我使用此正则表达式:

BlackPycharm: Cannot run program "/home/BCT/.local/bin/black -l80": error=2, File or folder not found

电子邮件通知现在看起来像这样:

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


或者这个:

使用用户名和密码登录:失败


“成功”文本为绿色,“失败”文本为红色

答案 1 :(得分:0)

似乎您可以使用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>

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