Hi,
I've put the first snippet in a file called utilities/MyUtilities.groovy and the second snippet in a file called dsl.groovy.
This is the output:
Processing DSL script dsl.groovy
Processing DSL script MyUtilities.groovy
java.lang.ClassCastException: org.codehaus.groovy.runtime.InvokerHelper$2 cannot be cast to javaposse.jobdsl.dsl.JobParent
at javaposse.jobdsl.dsl.DslScriptLoader.runDslEngineForParent(DslScriptLoader.java:70)
at javaposse.jobdsl.dsl.DslScriptLoader.runDslEngine(DslScriptLoader.java:132)
at javaposse.jobdsl.plugin.ExecuteDslScripts.perform(ExecuteDslScripts.java:220)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:785)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1741)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
ERROR: org.codehaus.groovy.runtime.InvokerHelper$2 cannot be cast to javaposse.jobdsl.dsl.JobParent
Finished: FAILURE
When I put both snippets in the same file and leave out the "package" and "import" lines then it works. That is, this works:
class MyUtilities {
static void addMyFeature(def job) {
job.with {
description('Arbitrary feature')
}
}
}
def myJob = job('example')
MyUtilities.addMyFeature(myJob)
What surprises me is that this (removing the last two lines) doesn't work (and results in the same error as above):
class MyUtilities {
static void addMyFeature(def job) {
job.with {
description('Arbitrary feature')
}
}
}
I'm using Jenkins 1.635 with Job DSL 1.40. The same happens with Job DSL 1.38.
Is anyone else having this error? Does the example work for others?
Thanks!
Kind regards,
Taco