12

We have a git repository with external submodules. We have to trigger a build when submodule was changed. Could you advice to us how to poll changes on submodules with your xtrigger plugin. Is it better to use shell script or monitor files or something else?


more information about our build brocess. step #1. clone root repository with submodules step #2. execute job for each submodule step #2.1 (in submodule). switch to proper branch (for example, master) step #2.1 (in submodule). pull the latest sources for submodule

now if somebody commits to root repository, jenkins launches build for the app but if somebody commits to any submodule repository, jenkins doesn't launch anything

we need solution for the second case. in best case it should be done via standard jenkins functionality or via open source plugin.

OJ287
  • 734
  • 1
  • 7
  • 15
  • Did you have a look into git hooks? – Chronial Dec 05 '12 at 11:37
  • no, could you expand your advise and explain it? – OJ287 Dec 05 '12 at 14:13
  • by the way, i think it's not a good idea because for hooks we need to configure server side of the repository. but this will complicate reguler work with repository. i want to perform all required configurations on the jenkins side. i've tried to use xtrigger plugin but unfortunately it doesn't work with git SCM. – OJ287 Dec 05 '12 at 14:16
  • Are you trying to use Jenkins to update the main repository to point to new commits in the submodule? i.e. is Jenkins expected to commit and push updates to your main repository? – asm Dec 05 '12 at 14:21
  • no, we just update sources for submodules. if everything goes well developer decides later which commit should be used for submodule in the main rep. jenknins doesn't commit anything to the main repository. – OJ287 Dec 05 '12 at 14:55
  • 1
    I see. In that case I would reverse your steps. Add a build that watches the submodule repositories in Jenkins (Step #2), run your submodule specific tests. If the submodule build completes have that trigger your main repository build. – asm Dec 05 '12 at 15:09
  • I would recommend using a post-recieve hook in your submodule repos that notifies jenkins. – Chronial Dec 05 '12 at 16:04

1 Answers1

8

When a git repository has a submodule it points to a specific commit in that submodule (say commit A). So even if the submodule changes and now has commit B as a child of A your top level repository is still pointing at commit A. You must explicitly update your top level repository to point at commit B in the submodule, it will not happen automatically.

Given this, the answer to your question is, just update your top level repository to point to the new commit B. This will cause a change in your repository which should trigger a Jenkins build just like it normally would, this will pick up the new commit B from the submodule.

--

Given the extra information I would add a Jenkins job that watches the submodule repositories. When a submodule changes do whatever submodule specific test you have then as a post build step trigger the main repository job.

asm
  • 8,758
  • 3
  • 27
  • 48
  • to clearify the situation i've added more information to origin description. please look at the "more information ...." section in the description. – OJ287 Dec 05 '12 at 14:11
  • 1
    In new versions of git (1.8.2) and later it is possible to point a submodule at HEAD or any branch rather than a specific commit. So this answer is no longer correct. – Fredrik E Oct 24 '13 at 11:48
  • 1
    I would do it like that. Have a dedicated Jenkins job which observes the submodule repository and acts as a trigger. When triggered, it updates the submodule reference and builds from the main repository. – Martin Komischke Dec 10 '13 at 13:31
  • @MartinKomischke this is the same use-case I have - as part of a CI job I want a Jenkins job based on the parent repository to auto-update a submodule when the _submodule_ changes (99% of the time due to a GitLab Merge Request being merged) - haven't figured out a way to do it yet... – davidA Jun 28 '18 at 22:55