Jenkins管道代码通过GitHub Organization Folder Plugin自动触发多个存储库

时间:2016-08-08 04:35:35

标签: jenkins jenkins-pipeline jenkinsfile github-organizations

此问题与具有多个存储库的Jenkins作业自动触发器有关。

在Jenkinsfile中定义了3个repo来结帐。

<item name="android:textColor">@color/black</item>

使用Github组织插件配置Jenkins作业。

在这种情况下,我的Jenkins文件在abc repo中,并且Jenkins自动触发器对于abc repo工作正常。它不适合其他回购。

有没有为2个或更多个回购定义自动触发?

是否有任何插件可以自动触发2个或更多存储库的作业?

我是否需要在Jenkinsfile中以不同方式定义“checkout scm”?

1 个答案:

答案 0 :(得分:7)

是的,您可以通过指定多个存储库(单击Pipeline script from SCM按钮)在管道作业中使用Add Repository选项执行此操作,假设您可以为3个存储库查看相同的分支,这似乎是你的情况。

enter image description here

使用此配置(当然还激活了Poll SCM选项),每次对三个存储库之一进行更改时都会触发构建。

关于此解决方案的一些提示:

  1. 您需要每个存储库中的Jenkinsfile
  2. 如果您在两个SCM polls之间提交了多个项目,结果将无法预测(您刚刚提交的两个项目中的任何一个最终都可以构建),因此您应该不依赖于哪个项目建成
  3. 要解决上一点并避免代码重复,您应该只从每个Jenkins文件加载一个通用脚本,例如:
  4. 在abc / def / ghi中的Jenkinsfile:

    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脚本:

    { ->
        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...
        }
    }
    
相关问题