Hi Nick, there is also another mailing list about JobDSL: - https://groups.google.com/forum/#!forum/job-dsl-plugin Besides of that, you can also use a similar approach as coded in the below git repo: - https://github.com/sheehan/job-dsl-gradle-example
It's object oriented based with some spock testing and gradle based, so you can easily test locally whether those DSLs work as expected. I believe you don't need the 4th argument in the basicJob function since that particular annotacion, correct me if I'm wrong, it's not used by the JobDSL plugin or whatsover,. You can use the with method as part of the closure and configure your job by using something like def basicJob(def jobName, def buildName, def jdk) { job(jobName) { description("Generated by a JobDSL. Do NOT edit manually!") label('Slave_Buildserver1') wrappers { preBuildCleanup() maskPasswords() timeout { absolute(180) } } } } basicJob("finishrelease", 'release', 'bla').with { steps { maven { mavenInstallation("Apache Maven 3.3.x") } } } Bear in mind, I just changed a bit to test the above snippet in the playground: - http://job-dsl.herokuapp.com/ Further details about class definitions - https://github.com/jenkinsci/job-dsl-plugin/wiki/Real-World-Examples#import-other-files-ie-with-class-definitions-into-your-script And It worked as expected. I hope it helps On Friday, 20 January 2017 10:10:02 UTC, Nick Stolwijk wrote: > > Hi all, > > I'm trying to avoid duplication in my jobDSL configuration by extracting > base functionality. > > It seems I'm failing. ;-) > > static void basicJob(def jobName, def buildName, def jdk, > @DslContext(FreeStyleJob) Closure closure) > FreeStyleJob job = freeStyleJob(jobName) { > description("Generated by a JobDSL. Do NOT edit manually!") > label('Slave_Buildserver1') > compressBuildLog() > wrappers { > preBuildCleanup() > maskPasswords() > buildName(buildName) > timeout { > absolute(180) > } > } > if(jdk) { > jdk(jdk) > } else { > jdk("JDK 8 64bits") > } > }; > ContextHelper.executeInContext(closure, job) > } > > basicJob("${componentName}/${reponame}/finishrelease", > '#${BUILD_NUMBER} release ${releaseVersion}', data.jdk) { > steps { > maven { > mavenInstallation("Apache Maven 3.3.x") > goals('--batch-mode clean verify') > } > } > > (I've simplified the above code somewhat) > > But I get the following error: workspace:/utilities/BasicUtilities.groovy: > 26: unexpected token: ContextHelper @ line 26, column 3. > ContextHelper.executeInContext(closure, > job) > > Are there any good blogs about refactoring DSL code? > What am I doing wrong? > > With regards, > > Nick Stolwijk > > ~~~ Try to leave this world a little better than you found it and, when > your turn comes to die, you can die happy in feeling that at any rate you > have not wasted your time but have done your best ~~~ > > Lord Baden-Powell > -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2d2f8aad-3a61-43ac-9588-2b452270e165%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.