how to get submodules to trigger a Jenkins build

前端 未结 2 1778
鱼传尺愫
鱼传尺愫 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.

    0 讨论(0)
  • 2021-01-01 05:23

    This can be done in two steps:

    1. Enable a build trigger url on the Jenkins job you want to build. This is done under "Trigger builds remotely" tab. The url will be in the form: JENKINS_URL/job/MY_JOB_NAME/build?token=TOKEN_NAME.

    2. Setup a git post-receive hook in submodule A that calls the above url. An easy way to do so is simply to use curl: curl JENKINS_URL/job/MY_JOB_NAME/build?token=TOKEN_NAME.

    A push to submodule A will then trigger the main project Jenkins's job by calling the url. Configure the Jenkins job to update its code before build or any other specifics you need.

    This answer provides a lot of details on how to setup the git hook.

    0 讨论(0)
提交回复
热议问题