I am having trouble configuring my job dsl for a github organization folder. I have tried to automate the discovery for the branches based on opened pull requests. I have tried to use the deprecated: buildOriginBranchWithPR(true)
without any success. I also tried my hand with: gitBranchDiscovery()
and gitTagDiscovery()
without much results either.
I know that the changes have several issues opened and that a few workaround have been proposed. One of them is to use the configure block from the job dsl to directly interact with the xml. I haven't managed to use it properly.
I have managed to make it work if I configure it with the GUI directly inside Jenkins but I would like to avoid that if possible.
Please see here an example of the job I am trying to define:
organizationFolder('example-org') {
description('This contains branch source jobs for example-org GitHub')
displayName('example-org')
triggers {
periodic(2400)
}
organizations {
github {
repoOwner("example-owner")
apiUri("https://api.github.com")
credentialsId('jenkins-token')
traits {
publicRepoPullRequestFilterTrait()
}
}
}
configure {
def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
traits << 'org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait' {
strategyId(2)
}
traits << 'org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait' {
strategyId(2)
}
}
projectFactories {
workflowMultiBranchProjectFactory {
// Relative location within the checkout of your Pipeline script.
scriptPath("Jenkinsfile")
}
}
}
I am using the last version from the official jenkins docker image.
Thanks in advance for your help.