how to get submodules to trigger a Jenkins build

前端 未结 2 1777
鱼传尺愫
鱼传尺愫 2021-01-01 04:42

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

2条回答
  •  时光说笑
    2021-01-01 05:03

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

    1. parent
      • Empty repo that just has submodules
    2. child-a
      • One child submodule repo
    3. child-b
      • The other child submodule repo

    When cloned with sub-modules it looks like:

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

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

    • 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)

    Repeat these steps for child-b


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

    • 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
    • Under Build Triggers check Build after other projects are built
      • 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

    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.

提交回复
热议问题