问题描述
如何添加默认的Suppress自动scm触发(命名分支除外)-Job DSL中的开发?
How do I add default Suppress automatic scm triggering except for named branch - development in Job DSL?
我尝试过文档 https://jenkinsci.github.io/job-dsl-plugin/# path/multibranchPipelineJob .没什么大不了的.似乎不受支持.
I tried docshttps://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob . It doesn't say much. Seems like it is not supported.
所以我想我唯一的方法是通过configure块将自定义属性直接添加到XML.
So I guess my only way is adding custom properties directly to XML via configure block.
我想要什么:
<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-Block.md
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.
现在我有了这个.它的工作原理是……
Now I have this. It works, sort of...
我能够生成作业,但是当我尝试重新保存作业时,詹金斯抛出错误.输出的XML有所不同.
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:
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')
}
}
}
}
}
}
}
这篇关于除了Jenkins Job DSL中的命名分支外,还添加了抑制自动scm触发功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!