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

Nit*_*tin 14 jenkins github-organizations jenkins-pipeline jenkinsfile

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

在Jenkinsfile中定义了3个repo来结账.

 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}
 }
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

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

Pom*_*m12 8

是的,您可以Pipeline script from SCM通过指定多个存储库(单击Add Repository按钮)来管理作业中的选项,假设您可以为3个存储库查看相同的分支,这似乎就是您的情况.

在此输入图像描述

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

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

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

Jenc文件在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'
}()
Run Code Online (Sandbox Code Playgroud)

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...
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 如果我需要为每个仓库建立不同的分支呢? (2认同)