Using Jenkins Job DSL after security fix to remove additonal classpath

Viewed 252

I see blogs talking about creating flexible enterprise capable Jenkins configurations using job dsl. Here are two of them:

https://blog.thesparktree.com/you-dont-know-jenkins-part-2 https://marcesher.com/2016/06/09/jenkins-as-code-job-dsl/

But since version 1.60 of the job dsl plugin, it is no longer possible to add to the classpath in the process job dsl build step (it is still recommended as an advanced strategy in this job dsl plugin help file https://github.com/jenkinsci/job-dsl-plugin/blob/master/docs/User-Power-Moves.md

My question is simple: is it still possbile to create flexible enterprise capable strategies using the job dsl plugin with the restriction and if so, how? Can people provide examples?

Thanks

1 Answers

After posting and without guidance with an answer I investigated and discovered that it is possible to have scripts call functions defined in other scripts. Here is how to do it:

GroovyShell shell = new GroovyShell()
def tools = shell.parse(new File("${WORKSPACE}/CONFIG_AS_CODE/vars/lib1.groovy"))
def j=job('dc/quick-gen') {
}
tools.goodLogRotation(j)
tools.goodJdk(j)

The following is the content of the file lib1.groovy

def goodLogRotation(job) {
    job.logRotator(4, 11)
}
def goodJdk(job) {
    job.jdk('jdk1.8.0_73')
}

This was based on this blog. Hope this provides useful. I will not vote up my own answer but I think it is quite cool.

Related