This can be done without git hooks. In this example we have 3 repos:
- parent
- Empty repo that just has submodules
- child-a
- 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.