问题
I'm trying to create a multi-line regex using the groovy post build plugin in Jenkins. I can make this work in the normal Jenkins script console, but I'm having trouble translating that to the post build plugin.
Here is the text I want to grab from the console log:
def string """
TEST SUMMARY:
[java] ------------------------------------------------------------
[java] 268 tests in 69 groups
[java] 1 errors
[java] 0 failures
"""
This line of code will match what I have above in the script console:
def match = string =~ /(?ms)(TEST SUMMARY.*?failures)/
I've tried several things with the post build plugin including the following:
manager.logContains((?ms)(".*TEST SUMMARY:.*?failures"))
and
def log = manager.build.logFile
def summary = log =~ /(?ms)(TEST SUMMARY.*?failures)/
and
def log = manager.build.logFile.text
def summary = log =~ /(?ms)(TEST SUMMARY.*?failures)/
回答1:
It turns out that the issue was a typo which was causing the regex to return 0 matches. For reference, in the event that someone else needs to do this the correct syntax is:
def log = manager.build.logFile.text
def summary = log =~ /(?ms)(TEST SUMMARY.*?failures)/
From there you can extract the matches or as in my case further parse the match:
def total = summary[0] =~ /\d+ tests/
来源:https://stackoverflow.com/questions/23139654/jenkins-groovy-post-build-plugin-multi-line-regex-on-console-log