цикл по массиву рабочих мест, чтобы создать их? - PullRequest
0 голосов
/ 03 июля 2018

У меня задание dsl, настроенное на удаление заданий без ссылок, и я хочу сохранить это: enter image description here

Я пытаюсь сделать это:

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

Дженкинс создает job1, но затем удаляет его при создании job2. Как зациклить список для создания нескольких рабочих мест?

Возможно, я смогу построить карту / замыкание multibranchPipelineJob objs и listView.jobs и передать его как-нибудь в dsl?

1 Ответ

0 голосов
/ 03 июля 2018

Я глуп, что сами работы фактически создавались нормально, их заменял только просмотр списка. Имеет смысл, потому что я воссоздаю один и тот же список для каждой итерации.

https://gist.github.com/kyounger/83134869ea523b3661f0

Мне просто пришлось убрать это из цикла:

listView('mylist') {
  jobs {
    jobsarry.each { job ->
      name(job)
    }
  }
  columns{
    status()
    weather()
    name()
    lastSuccess()
    lastFailure()
    lastDuration()
    buildButton()
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...