【问题标题】:How to make a Jenkins pipeline triggered by a pull request to build all the repositories in a Github project如何制作由拉取请求触发的 Jenkins 管道以构建 Github 项目中的所有存储库
【发布时间】:2020-02-13 21:35:05
【问题描述】:

我想设置一个由 GitHub 项目的拉取请求自动触发的管道,然后在其中构建所有存储库。我找到了这个article 并按照说明进行操作,因为它与我所需要的类似,但我目前一直坚持让管道触发并在同一个 GitHub 项目中构建多个存储库,每次 PR 甚至是其中一个存储库。

我已附上此 diagram,以便更清楚地了解我的问题。

所以目标是当在 Repository 1Branch 3 上发出拉取请求时,会触发管道,该管道会在指定的位置构建该分支和所有其他存储库顺序,即Working ProjectRepository 2Repository 3等。

您的帮助将不胜感激,我认为解决方案将使 CI DevOps 社区受益匪浅。谢谢!

【问题讨论】:

标签: jenkins github continuous-integration jenkins-pipeline pull-request


【解决方案1】:

试一试以下内容 - 不能保证以下内容是准确的,但应该能让您朝着正确的方向前进。

您要做的第一件事是在每个存储库中使用一致的 Jenkinsfile,现在您可以通过多种不同的方式做到这一点,但实现此目的的一种方法是使用外部 groovy 管道,以便逻辑可以在整个存储库中保持一致。这方面的一个例子位于here.。跨每个存储库复制 Jenkinsfile 也可以,但是单一的事实来源通常是更好的方法。

node{
    deleteDir()

    git env.flowScm
    def flow = load 'pipeline.groovy'
    stash includes: '**', name: 'flowFiles'

    stage 'Checkout'
    checkout scm // short hand for checking out the "from scm repository"

    flow.runFlow()
}

pipeline.groovy 文件包含实际管道的位置如下所示:

def runFlow() {
    // your pipeline code

} 

// Has to exit with 'return this;' in order to be used as library
return this;

一旦您使用相同的管道逻辑获得了每个触发器,您就可以利用dir 命令克隆和使用不是触发构建的存储库。这方面的一个例子位于here.

node('ATLAS && Linux') {
    dir('CalibrationResults') {
        git url: 'https://github.com/AtlasBID/CalibrationResults.git'
    }
    dir('Combination') {
        git url: 'https://github.com/AtlasBID/Combination.git'
    }
    dir('CombinationBuilder') {
        git url: 'https://github.com/AtlasBID/CombinationBuilder.git'
    }

    sh('ls')
    sh('. CombinationBuilder/build.sh')
}

将这两个步骤放在一起应该可以实现您在本例中所追求的目标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 2016-07-21
    • 2021-01-10
    • 2017-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多