我有一个DSL脚本来创建我的Jenkins管道作业。
String[] repos =
['xxx']
for (int i = 0; i < repos.length; i++) {
repoName = repos[i];
multibranchPipelineJob('PIPELINE-'+repoName) {
branchSources {
git {
remote('git@github.com:yyy/'+repoName+'.git')
credentialsId('112233445566')
}
}
description ("""<p> <b>generate by DSL - DO NOT CHANGE Manually </b> <p>""")
triggers {
periodic(2)
}
orphanedItemStrategy {
discardOldItems {
numToKeep(0)
daysToKeep(0)
}
}
}
}
答案 0 :(得分:4)
内置DSL不支持&#34;附加行为&#34;,但Automatically Generated DSL会:
multibranchPipelineJob('example-mbp2') {
branchSources {
branchSource {
source {
git {
id('bbedfd29-5bb0-4c13-b040-0dbd0d19345b')
remote('https://github.com/jenkinsci/job-dsl-plugin.git')
traits {
submoduleOptionTrait {
extension {
disableSubmodules(false)
recursiveSubmodules(true)
trackingSubmodules(false)
reference(null)
timeout(null)
parentCredentials(true)
}
}
}
}
}
}
}
}
答案 1 :(得分:3)
这是一个添加子模块标签和分支发现
的脚本multibranchPipelineJob('example') {
branchSources {
branchSource {
source {
git {
credentialsId('1111-2222-3333')
remote('git@github.com:xxx/yyyy.git')
traits {
submoduleOptionTrait {
extension {
disableSubmodules(false)
recursiveSubmodules(true)
trackingSubmodules(false)
reference(null)
timeout(null)
parentCredentials(true)
}
}
cloneOptionTrait {
extension {
shallow (false)
noTags (false)
reference (null)
depth(0)
honorRefspec (false)
timeout (10)
}
}
}
}
}
}
}
triggers {
periodic(2)
}
configure {
def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
traits << 'jenkins.plugins.git.traits.BranchDiscoveryTrait' {}
}
}