git参数插件:如何在pipline作业中分隔2个存储库?

时间:2017-10-12 10:24:44

标签: git jenkins groovy jenkins-plugins jenkins-pipeline

我在管道作业上使用git参数插件 我需要从两个不同的存储库获取所有分支 这是我的剧本

#!groovy
    node{
        checkout scm
        properties ([
                buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '3', daysToKeepStr: '', numToKeepStr: '5')),
                parameters([
                        [$class: 'GitParameterDefinition',
                         name: 'gitBranchCustomer',
                         description: ' branches projet 1',
                         type:'Branch',
                         branch: '',
                         branchFilter: '.*',
                         tagFilter:'*',
                         sortMode:'NONE',
                         defaultValue: '',
                         selectedValue:'NONE',
                         quickFilterEnabled: false],

                        [$class: 'GitParameterDefinition',
                         name: 'gitBranchCore',
                         description: 'branches projet 2',
                         type:'Branch',
                         branch: '',
                         branchFilter: '.*',
                         tagFilter:'*',
                         sortMode:'NONE',
                         defaultValue: '',
                         selectedValue:'NONE',
                         quickFilterEnabled: false],

                ])


        ])
        stage('select'){
            timeout(time:5){

                Environement = input( parameters: [ [$class: 'ChoiceParameterDefinition', choices: 'production\npreprod\nrecette', description: '', name: 'Environement : '] ])
                println "Property: $Environement"
                if(Environement.equals("production")){
                    Mode_de_livraison = input( parameters: [ [$class: 'ChoiceParameterDefinition', choices: 'Copie preprod\nRelivraison branche production', description: '', name: ' Mode de livraison : '] ])
                }else{
                    Mode_de_livraison = input(  parameters: [ [$class: 'ChoiceParameterDefinition', choices: 'Full\nRelivraison branche pre-production', description: '', name: ' Mode de livraison : '] ])
                }
                println "Property: $Mode_de_livraison"
            }
        }

        //stage('checkout') {git branch: "master", credentialsId: '2d43b72d-fadc-446c-aaff-050a904b8ba9', url: 'https://github.com/mouadiativ/formation-test-1.git'}
    }

问题是它在一个参数中重新组合所有分支 enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要至少一次签出要使用的所有存储库,以便Jenkins保存有关SCM的信息。 您可以只使用git DSL签出其他远程服务器(“ SCM管道”之外),将其插入管道中并运行一次管道:

#!groovy
    node{
        git branch: "master", credentialsId: CRED_ID, url: URL
        checkout scm
        return // this will end build
        properties ([
                buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '3', daysToKeepStr: '', numToKeepStr: '5')),
                parameters([...

然后在GitParameterDefinition中有一个useRepository参数,您可以在一个git参数中将其设置为customer并在另一个core中进行设置(如果这些是您的名称回购):

                parameters([
                        [$class: 'GitParameterDefinition',
                         name: 'gitBranchCustomer',
                         description: ' branches projet 1',
                         type:'Branch',
                         branch: '',
                         branchFilter: '.*',
                         tagFilter:'*',
                         sortMode:'NONE',
                         defaultValue: '',
                         selectedValue:'NONE',
                         quickFilterEnabled: false,
                         useRepository: 'customer'], // < ------ here

                        [$class: 'GitParameterDefinition',
                         name: 'gitBranchCore',
                         description: 'branches projet 2',
                         type:'Branch',
                         branch: '',
                         branchFilter: '.*',
                         tagFilter:'*',
                         sortMode:'NONE',
                         defaultValue: '',
                         selectedValue:'NONE',
                         quickFilterEnabled: false,
                         useRepository: 'core'] // < ------ and here

                ])
相关问题