我如何添加默认的Scmpress自动scm触发,除了命名分支-Job DSL中的开发?
我尝试了文档 https://jenkinsci.github.io/job-dsl- plugin/#path/multibranchPipelineJob。没多说。似乎不被支持。
因此,我想我唯一的方法是通过configure块将自定义属性直接添加到XML。
我想要的是:
<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>
我尝试过的
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') } } } }
这很有用,但会不断崩溃http://job-dsl.herokuapp.com/ 这不是很有用https://github.com/jenkinsci/job-dsl-plugin/blob/master/docs/The- Configure-块.md
我不知道自己在做什么,文档,手册和教程根本没有帮助。
编辑:
现在我有了这个。它可以工作,有点…
我能够生成作业,但是当我尝试重新保存作业时,詹金斯抛出错误。输出XML有所不同。
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') } } } } } }
}
您可能已经注意到,它非常丑陋。希望将来有人会修复该插件。
因此,有效的代码如下:
UUID uuid = UUID.randomUUID() println('Random UUID: ' + uuid) multibranchPipelineJob('test') { configure { it / sources / 'data' / 'jenkins.branch.BranchSource' << { source(class: 'jenkins.plugins.git.GitSCMSource') { id(uuid) remote('...') credentialsId('...') includes('*') excludes('') ignoreOnPushNotifications('false') traits { 'jenkins.plugins.git.traits.BranchDiscoveryTrait'() } } strategy(class: 'jenkins.branch.NamedExceptionsBranchPropertyStrategy') { defaultProperties(class: 'empty-list') namedExceptions(class: 'java.util.Arrays\$ArrayList') { a(class: 'jenkins.branch.NamedExceptionsBranchPropertyStrategy\$Named-array') { 'jenkins.branch.NamedExceptionsBranchPropertyStrategy_-Named'() { props(class: 'java.util.Arrays\$ArrayList') { a(class: 'jenkins.branch.BranchProperty-array') { 'jenkins.branch.NoTriggerBranchProperty'() } } name('master') } } } } } } }