warnings plugin groovy script

188 views
Skip to first unread message

Alex

unread,
Mar 22, 2017, 1:39:18 PM3/22/17
to Jenkins Users
Hello,

I am trying to automate the creation of a parser for the warnings plugin.

So far I have this groovy code 


import hudson.plugins.warnings.*;
def rubocop_name = 'Rubocop';
def rubocop_regexp = "^([^:]+):(\\d+):\\d+: ([^:]): ([^:]+)\$";
def rubocop_script = '''
import hudson.plugins.warnings.parser.Warning

String fileName = matcher.group(1)
String lineNumber = matcher.group(2)
String category = matcher.group(3)
String message = matcher.group(4)

return new Warning(fileName, Integer.parseInt(lineNumber), "Ruby Lint Warnings", category, message);
'''
def rubocop_example = "'attributes/default.rb:21:78: C: Use %r only for regular expressions matching more than 1 '/' character.'";
def rubocop_link = 'RuboCop';
def rubocop_trend = 'Ruby Lint Warnings';

def RuboCop = new GroovyParser (
  rubocop_name,
  rubocop_regexp,
  rubocop_script,
  rubocop_example,
  rubocop_link,
  rubocop_trend
  )

I couldn't find a method that saves this and makes this visibile in Configure Jenkins -> Compiler Warnings.

Thanks

Ewelina Wilkosz

unread,
Mar 23, 2017, 12:06:22 PM3/23/17
to Jenkins Users
I think you may need to use descriptor

def warningDesc = Jenkins.getInstance().getDescriptor(hudson.plugins.warnings.WarningsPublisher)

and then add the parser with it:

warningDesc.addGroovyParser(RuboCop)

Although I'm not 100% sure :) let me know when if you try that

Alex

unread,
Mar 28, 2017, 6:07:44 AM3/28/17
to Jenkins Users
It works like that. Thank you very much :)
Reply all
Reply to author
Forward
0 new messages