Jenkins pipeline code auto trigger with multiple repositories through GitHub Organization Folder Plugin

后端 未结 1 941
借酒劲吻你
借酒劲吻你 2021-02-19 03:26

This question is related to the Jenkins job auto trigger with multiple repositories.

Defined 3 repo\'s to checkout in Jenkinsfile.

 node(\'slave\'){
 git         


        
1条回答
  •  再見小時候
    2021-02-19 04:11

    Yes, you can do that with the Pipeline script from SCM option in a pipeline job by specifying multiple repositories (click on Add Repository button), assuming you can watch the same branch for your 3 repositories, which seems to be your case.

    With this configuration (and of course the Poll SCM option activated), a build will be triggered every time a change is made to one of your three repositories.

    A few more hints about this solution:

    1. You need a Jenkinsfile in each repository
    2. If you commited on more than one project between two SCM polls the result will be unpredictable (either one of the two projects you just committed in could finally get built) so you should not depend on which project gets built.
    3. To solve previous point and also avoid code duplication, you should probably just load a generic script from each of your Jenkinsfile, such as:

    Jenkinsfile in abc/def/ghi:

    node {
        // --- Load the generic pipeline ---
        checkout scm: [$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'http://github/owner/pipeline-repo.git']]]
        load 'common-pipeline.groovy'
    }()
    

    common-pipeline.groovy script:

    { ->
        node() {
           git clone github.com/owner/abc.git
           git clone github.com/owner/def.git
           git clone github.com/owner/ghi.git            
    
           // Whatever you do with your 3 repos...
        }
    }
    

    0 讨论(0)
提交回复
热议问题