Jenkins 循环创建一系列作业?
我已将dsl作业配置为删除未引用的作业,并希望保留该作业: 我正在努力做到这一点:Jenkins 循环创建一系列作业?,jenkins,jenkins-plugins,jenkins-job-dsl,Jenkins,Jenkins Plugins,Jenkins Job Dsl,我已将dsl作业配置为删除未引用的作业,并希望保留该作业: 我正在努力做到这一点: def bitbucket_team = 'myteam' def bitbucket_user = 'mycreds' def repo_arr = ['job1','job2'] repo_arr.collect { repo -> println "${repo}" multibranchPipelineJob("${repo}") { configure {
def bitbucket_team = 'myteam'
def bitbucket_user = 'mycreds'
def repo_arr = ['job1','job2']
repo_arr.collect { repo ->
println "${repo}"
multibranchPipelineJob("${repo}") {
configure {
it / sources / data / 'jenkins.branch.BranchSource' / source(class: 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource') {
credentialsId("${bitbucket_user}")
//checkoutCredentialsId('bitbucket-ssh-key') // can use ssh key here instead of a BB user
repoOwner("${bitbucket_team}")
repository("${repo}")
includes('*')
excludes()
traits {
'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait'() {
strategyId(1) // Exclude branches that are also filed as PRs
//strategyId(2) // Only branches that are also filed as PRs
//strategyId(3) // All branches
}
'com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait'() {
strategyId(1)
}
'com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait'(){
strategyId(1) // Merging the pull request with the current target branch revision
//strategyId(2) // The current pull request revision
//strategyId(3) // Both the current pull request revision and the pull request merged with the current target branch revision
//Default to trust forks in same account
}
'com.cloudbees.jenkins.plugins.bitbucket.WebhookRegistrationTrait'() {
mode('ITEM')
}
}
}
}
}
// Add jobs to a list view
listView('myview') {
jobs {
name("${repo}")
}
columns{
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
}
}
} // End repo_arr.collect
Jenkins创建job1,但在创建job2时将其删除。如何循环列表以创建多个作业
也许我可以构建一个multibranchPipelineJob OBJ和listView.jobs的映射/闭包,并以某种方式将其传递给dsl?Im dumb作业本身实际上创建得很好,只是listView取代了它们。这很有意义,因为我在为每个迭代重新创建相同的listview 我只需要把它从循环中移出:
listView('mylist') {
jobs {
jobsarry.each { job ->
name(job)
}
}
columns{
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
}
}
我很傻,这些工作实际上是很好地创造出来的,只是listview取代了它们。这很有意义,因为我在为每个迭代重新创建相同的listview 我只需要把它从循环中移出:
listView('mylist') {
jobs {
jobsarry.each { job ->
name(job)
}
}
columns{
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
}
}