上游工作的Jenkins Clone / Checkout Git存储库

时间:2017-11-24 18:40:05

标签: git bash powershell github jenkins

问题

我正在詹金斯的一家工厂工作,并开始检查或克隆一个基于上游工作已经签出的Git存储库。

EX: Job A uses Git Repo 1
    Job B uses Git Repo 2
    Job C uses Git Repo 3
    Job D is the Factory Job

    Job D is called by Jobs A - C upon successful build

    If Job A calls Job D, Job D clones/checks out Repo 1 and performs its tasks using that Repo
    If Job B calls Job D, Job D clones/checks out Repo 2 and performs its tasks using that Repo
    If Job C calls Job D, Job D clones/checks out Repo 3 and performs its tasks using that Repo

我一直在寻找如何做到这一点,如果有可能,现在几个小时......我发现最接近的事情是如何将多个存储库加载到一个工作中#39;这不是我想做的事情,特别是因为随着更多的存储库及时添加,它可能会导致Job不断增长。这对我来说似乎没有适当的可扩展性。

问题

在Jenkins中,下游作业是否有合理的可扩展方式来克隆/签出上游作业在触发下游作业时使用的相同Git存储库?

2 个答案:

答案 0 :(得分:1)

使用git_url等参数定义作业D,并在git存储库url中使用此变量,然后使用参数化触发器插件(https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin)从任何上游作业调用它。

答案 1 :(得分:0)

插件https://wiki.jenkins.io/display/JENKINS/Parameterized+Trigger+Plugin可用于触发参数化构建,作为向下游传递参数的构建后操作。因此,如果将Factory作业设置为参数化,则可以使用上游作业的参数。

解决方案如下所示:

EX: Job A uses Git Repo 1
    Job B uses Git Repo 2
    Job C uses Git Repo 3
    Job D is the Factory Job parameterized with P

    Jobs A - C triggers D as parameterized build
        with predefined parameter P upon successful build
        let P be Repo 1 - 3 according to Job A - C

    If Job A calls Job D, Job D clones/checks out P and performs its tasks using that Repo
    If Job B calls Job D, Job D clones/checks out P and performs its tasks using that Repo
    If Job C calls Job D, Job D clones/checks out P and performs its tasks using that Repo