Jenkins Groovy post build plugin multi line regex on console log

时光毁灭记忆、已成空白 提交于 2019-12-11 04:03:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!