Jenkins管道代码通过GitHub Organization Folder插件自动触发多个存储库 [英] Jenkins pipeline code auto trigger with multiple repositories through GitHub Organization Folder Plugin

查看:544
本文介绍了Jenkins管道代码通过GitHub Organization Folder插件自动触发多个存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

在Jenkinsfile中定义了3个要回购的仓库.

Defined 3 repo's to checkout in Jenkinsfile.

 node('slave'){
 git clone github.com/owner/abc.git -b ${env.BRANCH_NAME}
 git clone github.com/owner/def.git -b ${env.BRANCH_NAME}
 git clone github.com/owner/ghi.git -b ${env.BRANCH_NAME}
 }

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

Configured Jenkins job using Github organization plugin.

在这种情况下,我的Jenkinsfile位于abc仓库中,而Jenkins自动触发器在abc仓库中工作正常.它不适用于其他回购协议.

In this case my Jenkinsfile is in abc repo and the Jenkins auto trigger is working fine for the abc repo. its not working for other repo's.

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

Is there anyway to define auto trigger for 2 or more repo's?

有没有可以自动触发2个或更多存储库的插件?

Is there any plugin which can auto trigger job for 2 or more repositories?

我需要在Jenkinsfile中以不同的方式定义"checkout scm"吗?

Do I need to define "checkout scm" different way in Jenkinsfile?

推荐答案

是的,您可以在管道作业中使用Pipeline script from SCM选项,通过指定多个存储库(单击Add Repository按钮)来做到这一点,假设您可以观看您的3个存储库的同一个分支,这似乎是您的情况.

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.

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

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. 每个存储库中需要 a Jenkinsfile
  2. 如果您在两个SCM polls之间提交了多个项目,结果将是不可预测的(您刚刚提交的两个项目中的一个都可能最终被构建),因此您不应该依赖于要构建的项目.
  3. 要解决上述问题并避免重复代码,您可能应该仅从每个Jenkinsfile加载通用脚本,例如:
  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:

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

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...
    }
}

这篇关于Jenkins管道代码通过GitHub Organization Folder插件自动触发多个存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆