Vadim  Kovrizhkin
Vadim Kovrizhkin

Reputation: 1781

Groovy Postbuild Plugin manager.getLogMatcher regex returns null if parentheses are present in string

Jenkins Groovy Postbuild Plugin manager.getLogMatcher regex returns null if parentheses are present in string.

Jenkins console output contains string:

(origin/pull-requests/1365/merge)

I need to get number from string 1365 and use:

manager.getLogMatcher("^origin/pull-requests/(.*?)/merge*").matches()

it fails with:

Java.lang.NullPointerException: Cannot invoke method matches() on null object

but if I delete parentheses:

origin/pull-requests/1365/merge

everything is ok.

Upvotes: 0

Views: 3524

Answers (1)

Opal
Opal

Reputation: 84804

If you look at the sources you'll find that the method you invoke may eventually return a null reference. Since you regular expression is invalid I guess this is the case. You need to take the parenthesis into consideration - especially if you regex starts with ^. The two following should work:

"^\\(origin/pull-requests/(.*?)/merge.*"
^\\(origin/pull-requests/(.*?)/merge\\)

Upvotes: 2

Related Questions