How do I add default Suppress automatic scm triggering except for named branch - development in Job DSL?
I tried docs https://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob . It doesn't say much. Seems like it is not supported.
So I guess my only way is adding custom properties directly to XML via configure block.
What I want:
<strategy class="jenkins.branch.NamedExceptionsBranchPropertyStrategy">
<defaultProperties class="java.util.Arrays$ArrayList">
<a class="jenkins.branch.BranchProperty-array">
<jenkins.branch.NoTriggerBranchProperty/>
</a>
</defaultProperties>
<namedExceptions class="java.util.Arrays$ArrayList">
<a class="jenkins.branch.NamedExceptionsBranchPropertyStrategy$Named-array">
<jenkins.branch.NamedExceptionsBranchPropertyStrategy_-Named>
<props class="empty-list"/>
<name>development</name>
</jenkins.branch.NamedExceptionsBranchPropertyStrategy_-Named>
</a>
</namedExceptions>
</strategy>
What I've tried:
multibranchPipelineJob(jobName) {
branchSources {
git {
remote(gitRepo)
credentialsId(credentials)
includes('*')
configure {
it / "sources class='jenkins.branch.MultiBranchProject$BranchSourceList'" / 'data' / 'jenkins.branch.BranchSource' / "strategy class='jenkins.branch.DefaultBranchPropertyStrategy'" << name('development')
}
}
}
}
This is useful, but keeps crashing http://job-dsl.herokuapp.com/ This is not so useful https://github.com/jenkinsci/job-dsl-plugin/blob/master/docs/The-Configure-Block.md
I have no idea what I'm doing and the docs, manuals and tutorials are not helpful at all.
EDIT:
Now I have this. It works, sort of...
I'm able to generate the job, but Jenkins throws an error when I try to resave the job. The output XML is somehow different.
multibranchPipelineJob(jobName) {
configure {
it / sources(class: 'jenkins.branch.MultiBranchProject$BranchSourceList') / 'data' / 'jenkins.branch.BranchSource' << {
source(class: 'jenkins.plugins.git.GitSCMSource') {
id(randomId)
remote(gitRepo)
credentialsId(credentials)
}
strategy(class: "jenkins.branch.NamedExceptionsBranchPropertyStrategy") {
defaultProperties(class: "java.util.Arrays\$ArrayList") {
a(class: "jenkins.branch.BranchProperty-array") {
'jenkins.branch.NoTriggerBranchProperty'()
}
}
namedExceptions(class: "java.util.Arrays\$ArrayList") {
a(class: "jenkins.branch.NamedExceptionsBranchPropertyStrategy\$Named-array") {
'jenkins.branch.NamedExceptionsBranchPropertyStrategy_-Named'() {
props(class: "empty-list")
name('development')
}
}
}
}
}
}
}
As you might have noticed, it is extremely ugly. Hopefully someone will fix the plugin in the future.
So the code which is working is the following:
You can achieve this in two ways