Can't get log info with Groovy Postbuild Plugin

143 views
Skip to first unread message

Rob D

unread,
Dec 10, 2014, 7:40:53 PM12/10/14
to jenkins...@googlegroups.com
I'm using the Groovy Postbuild Plugin in Jenkins on Windows 7. I was trying to match strings in a file but when that failed, I reduced it to the point where I am just searching for a string in another string. It will never find a match. I must be misunderstanding how Groovy works or else it just isn't working in this plugin. Please tell me what I am doing wrong.

def txt = "slkd Cskk sdwo Csks swkdCsksl"
def matcher = txt  =~ /Cs/ 
if(matcher.matches()){
   manager.addShortText("match")
}
else {
   manager.addShortText("no match")
}

Thanks,
Rob

Daniel Beck

unread,
Dec 10, 2014, 8:47:50 PM12/10/14
to jenkins...@googlegroups.com
On 11.12.2014, at 01:40, Rob D <robds...@gmail.com> wrote:

> Please tell me what I am doing wrong.

From http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html, emphasis mine:

> • The matches method attempts to match the __entire input sequence__ against the pattern.
> • The find method scans the input sequence looking for __the next subsequence__ that matches the pattern.

Since `txt` is clearly not the string 'Cs', it doesn't _match_.

Using something line /.*Cs.*/ may be an option for you, like the examples on https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin do it.

General troubleshooting hint: Try to remove as many components as possible from your problem to determine where the problem lies. In this case, a simple standalone Groovy script would have demonstrated that the problem has nothing to do with Groovy Postbuild, or Jenkins even.

Reply all
Reply to author
Forward
0 new messages