Calling the DSL factory from another Jenkins plug-in - MissingMethodException but signature OK

279 views
Skip to first unread message

Damien Coraboeuf

unread,
Apr 25, 2015, 2:54:16 PM4/25/15
to job-dsl...@googlegroups.com
Hi,

I'm currently designing a Jenkins plug-in which calls some Job DSL script. In order to allow for more flexibility, I want to call the DSL directly, using code like:

JenkinsJobManagement jm = new JenkinsJobManagement(...)
JobParent jobParent = new JobParent() {
   
@Override
    public Object run() {
       
return null;
   
}
}
jobParent.setJm(jm)
jobParent.folder('test') {
}
jobParent
.freeStyleJob('test/test-job') {
   description
'Test job'
}

This compiles fine, but running this results in a MissingMethodException:

groovy.lang.MissingMethodException:
No signature of method: net.nemerosa.seed.jenkins.step.ProjectSeedBuilder$1.folder() is applicable for argument types: (java.lang.String, net.nemerosa.seed.jenkins.step.ProjectSeedGenerator$_generate_closure1) values: [test, net.nemerosa.seed.jenkins.step.ProjectSeedGenerator$_generate_closure1@4ca13c39]

The signature method looks OK to me: String, then Closure.

Any idea of a solution to this problem?

My goal remains to be able to call the DSL directly from another plug-in.

Note that this works fine when running as a unit test, but not inside a Jenkins instance itself.

Best regards,
Damien.

Damien Coraboeuf

unread,
Apr 26, 2015, 7:56:56 AM4/26/15
to job-dsl...@googlegroups.com
When I split the call in different parts:

def myJob = dslFactory.freeStyleJob('test')
myJob
.description "My description"

instead of:

def myJob = dslFactory.freeStyleJob('test') {
   description "My description"
}

it works. But this is of course not satisfying, and does not work for more complex situations (parameters, steps, etc.).

This makes me think that the Closure passed as a parameter, annotated with @DslContext, has something to do with the MissingMethodException. Probably some preconditions or processing is not done or met, making a direct call impossible (it works fine when the same code is called using a script though).

In my very case, I'd like to call the DSL directly, without relying on a script, since I use my plug-in to generate some other jobs, with many conditions and switches.

Thanks for any hint,
Damien
Reply all
Reply to author
Forward
0 new messages