[英]How to capture second string using groovy script from jenkins console
I need to configure rspec test case run count on a jenkins job. 我需要在jenkins作业上配置rspec测试用例的运行次数。 Below is the format of the entry in the jenkin console after test run.
以下是测试运行后jenkin控制台中条目的格式。
3 examples, 0 failures
6 examples, 0 failures
We have such entry twice in console as shown above (because of 2 ruby script run). 如上图所示,我们在控制台中有两次这样的输入(因为运行了2个ruby脚本)。 So after all the runs, when build is done, I need to capture both the entry and display at the job shown at Build History in jenkins.
因此,在所有运行之后,完成构建后,我需要捕获条目并在jenkins的“构建历史”中显示的工作中显示。
So to capture the above count now I am using below groovy script at groovy Postbuild of jenkin configuration. 因此,现在要捕获以上计数,我在詹金配置的groovy Postbuild中使用以下groovy脚本。 But it picks just the first match of the string from the jenkins console:
但是它只是从jenkins控制台中选择字符串的第一个匹配项:
matcher = manager.getLogMatcher("(.*) examples, (.*) failures")
if(matcher != null && matcher.matches()) {
totalTests = matcher.group(1)
failedTests = matcher.group(2)
description += "<br/>UI Tests: total: ${totalTests}, Fail: ${failedTests}"
}
How do I do to get 2, 3rd match of entry from jenkins console: 我要如何从jenkins控制台中获得2、3rd匹配项:
You can also try with build.getLog(int maximumLines), and then parse the output with regex. 您也可以尝试使用build.getLog(int maximumLines),然后使用正则表达式解析输出。 For example:
例如:
def buildLog = manager.build.getLog(10) // you might need to change the amount of maximum lines
def group = (buildLog =~ /(\d+) examples, (\d+) failures/ )
for(int i=0; i<group.size();i++) {
manager.createSummary("info.gif").appendText("examples: ${group[i][1]}, failures: ${group[i][2]}", false)
}
in this case, the results would be added to the each build info. 在这种情况下,结果将添加到每个构建信息中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.