I need to configure rspec test case run count on a jenkins job. Below is the format of the entry in the jenkin console after test run.
3 examples, 0 failures
6 examples, 0 failures
We have such entry twice in console as shown above (because of 2 ruby script run). 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.
So to capture the above count now I am using below groovy script at groovy Postbuild of jenkin configuration. But it picks just the first match of the string from the jenkins console:
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:
You can also try with build.getLog(int maximumLines), and then parse the output with regex. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.