Jenkins 发送包含部分日志行的电子邮件
Jenkins send email with part of log line
我在 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"
有什么方法可以只用那一行的一部分发送电子邮件吗?
您似乎可以使用 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>
这将仅匹配示例中的最后一行,select 第一个捕获组中的 success/failure 状态,将在替换模式中引用。
感谢亚伦,我找到了解决方案。
现在我使用这个正则表达式:
<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" 文本为绿色,"FAILED" 文本为红色
我在 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"
有什么方法可以只用那一行的一部分发送电子邮件吗?
您似乎可以使用 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>
这将仅匹配示例中的最后一行,select 第一个捕获组中的 success/failure 状态,将在替换模式中引用。
感谢亚伦,我找到了解决方案。
现在我使用这个正则表达式:
<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" 文本为绿色,"FAILED" 文本为红色