| I also faced this issue. I end up adding a build step on my job : 1st step: Creation of the pipeline if it do not exist:
hudson.model.Item i=jenkins.model.Jenkins.instance.getItemByFullName("$folder/$name")
if (i!=null){
throw new javaposse.jobdsl.dsl.DslException("$folder/$name already exist")
}
multibranchPipelineJob("$folder/$name") {
description("")
...
branchSources {
branchSource {
source {
github {
id(UUID.randomUUID().toString())
...
}
}
strategy {
...
}
}
}
factory {
workflowBranchProjectFactory {
scriptPath("Jenkinsfile")
}
}
}
Then on another step, I execute the post action that are not triggered :
println("Initializing job")
hudson.model.Item i=jenkins.model.Jenkins.instance.getItemByFullName("$folder/$name")
println("Job found: "+i.getDisplayName())
i.save()
i.getSCMSources().get(0).afterSave()
queue("$folder/$name")
println("Inializing done")
I save the job (I'm not sure it is needed, but it make the configuration file much like it is if I do it manually) then I trigger the "afterSave()" method on the SCM source (In github use-case, it adds the Webhook on the repo ) and finally I trigger a build of the multibranch so that branch are scanned. JobDSL is generic, so I'm not sure one day it will be able to do that, but until then, this will do the trick .... I hope ... |