0

我在 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"

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

4

2 回答 2

2

感谢 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>

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

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


或这个:

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


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

于 2018-12-10T13:58:48.357 回答
0

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

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

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

于 2018-12-06T13:42:32.293 回答