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
This can be done without git hooks. In this example we have 3 repos:
When cloned with sub-modules it looks like:
parent\
child-a\*
child-b\*
In Jenkins create a freestyle project called dummy-child-a
.
Source Code Management
setup the Repository URL
for child-a
Build Triggers
you choose Poll SCM
and set your desired interval Build
click Add build step
Execute Windows batch command
or Execute shell
depending on your OSecho 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
Source Code Management
setup the Repository URL
for parent
add
under Additional Behaviours
and choose Advanced sub-modules behaviours
Recursively update submodules
Update tracking submodules to tip of branch
Use credentials from default remote of parent repository
Build Triggers
check Build after other projects are built
Projects to watch
field, fill all projects to watch with comma separation: dummy-child-a, dummy-child-b
parent
doesn't have source code that will change, You don't need to Poll SCM
on this Jenkins jobTrigger 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.
This can be done in two steps:
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
.
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.