更新时间:2023-12-05 13:56:22
看起来像JVM不喜欢带连字符的类名。
通过在内部调用脚本 Set-BuildBadge.groovy
,它被编译成一个不允许的类您将一个函数添加到脚本中。
将脚本名称更改为 SetBuildBadge.groovy
将解决此问题: - )
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?
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 :-)