如何获取子模块以触发Jenkins构建 [英] how to get submodules to trigger a Jenkins build

查看:709
本文介绍了如何获取子模块以触发Jenkins构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不是独立应用程序的子模块A.它需要主要的应用程序才能运行.我想为A创建一个CI构建,以便每当将提交推送到A时,它就会触发带有主要项目代码的构建.

I have a submodule A that is not a standalone application. It requires the main application for it to work. I would like to create a CI build for A so that whenever a commit is pushed to A it triggers a build with the main project code.

我如何在詹金斯做到这一点?

How do I do that in Jenkins?

我需要做什么:

  • 对A的提交会触发构建.
  • 内部版本会克隆Main项目代码,并在A的最新提交(不是Main Project知道的提交)时拉取A的最新代码.

我如何使用Jenkins和GIT来做到这一点?

How would I do that using Jenkins and GIT?

请注意,我有该项目的多个子模块.子模块A触发了一个构建,该构建从A中获取最新更改,并从主代码中获取最新更改,并从其他子模块中获取更新.

Note I have multiple submodules for the project. Submodule A triggers a build that pulls the latest changes from A and also the latest of main code and pulls updates from the other submodules.

推荐答案

这可以在没有git钩子的情况下完成.在此示例中,我们有3个存储库:

This can be done without git hooks. In this example we have 3 repos:

  1. 父母
    • 只有子模块的空仓库
  1. parent
    • Empty repo that just has submodules
  • 一个子子模块存储库
  • 另一个子子模块存储库

与子模块一起克隆时,它看起来像:

When cloned with sub-modules it looks like:

parent\
    child-a\*
    child-b\*


在Jenkins中创建一个名为dummy-child-a的自由式项目.


In Jenkins create a freestyle project called dummy-child-a.

  • Source Code Management下,将Repository URL设置为child-a
  • Build Triggers下,选择Poll SCM并设置所需的时间间隔
  • Build下,单击Add build step
    • 根据您的操作系统选择Execute Windows batch commandExecute shell
    • 在脚本框中执行类似echo hello的操作(这是虚拟部分)
    • Under Source Code Management setup the Repository URL for child-a
    • Under Build Triggers you choose Poll SCM and set your desired interval
    • Under Build click Add build step
      • Choose Execute Windows batch command or Execute shell depending on your OS
      • In the script box do something like echo hello (this is the dummy part)

      child-b

      在Jenkins中创建一个名为parent的自由式项目.这是我们实际要做的地方

      In Jenkins create a freestyle project called parent. This is where we will actually do the building

      • Source Code Management下,将Repository URL设置为parent
      • 单击Additional Behaviours下的add,然后选择Advanced sub-modules behaviours
        • 检查:
        • Recursively update submodules
        • Update tracking submodules to tip of branch
        • Use credentials from default remote of parent repository
        • Under Source Code Management setup the Repository URL for parent
        • Click add under Additional Behaviours and choose Advanced sub-modules behaviours
          • Check:
          • Recursively update submodules
          • Update tracking submodules to tip of branch
          • Use credentials from default remote of parent repository
          • Projects to watch字段中,以逗号分隔的形式填充所有要观看的项目:dummy-child-a, dummy-child-b
          • 如果parent没有可更改的源代码,则您无需Poll SCM进行此詹金斯工作
          • 检查Trigger even if the build fails
          • In the Projects to watch field, fill all projects to watch with comma separation: dummy-child-a, dummy-child-b
          • If parent doesn't have source code that will change, You don't need to Poll SCM on this Jenkins job
          • Check Trigger even if the build fails

          您已经完成.对子级a或子级b的任何更改都会触发父级的重建.此方法假定父级中子模块的数量很少更改.如果要添加另一个子模块,则需要创建另一个dummy项目,然后更新parent Jenkins版本的projects to watch.

          And you're done. Any changes to either child-a or child-b will trigger a rebuild of parent. This method assumes that the number of submodules in parent changes infrequently. If you were to add another submodule you would need to make another dummy project, and then update the projects to watch of the parent Jenkins build.

          这篇关于如何获取子模块以触发Jenkins构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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