简体   繁体   中英

Jenkins Groovy post build plugin multi line regex on console log

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)/

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/

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM