4
votes

I'm using the following code in post-build step of my Jenkins job:

evaluate(new File("Set-BuildBadge.groovy"));

So it runs a script successfully if it does not contain functions.

If inside the script I define a function for example:

def addSummaryWithText(Icon, Text) {
    manager.createSummary(Icon).appendText(Text, false)
}
...
addSummaryWithText("installer.gif", "Project: " + ProjectName)

then I get the following error:

FATAL: Illegal class name "Set-BuildBadge$addSummaryWithText" in class file Set-BuildBadge$addSummaryWithText java.lang.ClassFormatError: Illegal class name "Set-BuildBadge$addSummaryWithText" in class file Set-BuildBadge$addSummaryWithText at java.lang.ClassLoader.defineClass1(Native Method) ...

I'm not getting how GroovyShell.evaluate works. Can anyone help me?

1
Can you try without a hyphen in the script name? - tim_yates
Genious! I've lost 3 hours digging into groovy (new to me) and solution was just to remove hypen ))) - Ivan
added as an answer! :-) Glad it's resolved! Have fun! - tim_yates
Thanks a lot, mate! Awesome reputation by the way... - Ivan
Haha, no worries! And ta...not sure if it's a good thing, or a sign of some mild underlying addiction ;-) - tim_yates

1 Answers

11
votes

Looks like the JVM doesn't like class names with a hyphen in them.

By calling your script Set-BuildBadge.groovy internally it is compiled into a class that isn't allowed when you add a function to the script.

Changing the name of the script to SetBuildBadge.groovy will fix it :-)