3

Jenkins is on a detached head. Whenever a submodule gets updated, I need to trigger a build. However, only the main project gets cloned.

Two questions

  • How do I tell Jenkins to trigger a build when a submodule gets updated, but not clone the submodule? I need the main project code cloned instead, but Jenkins still needs to start the build only when the submodule gets updated. So let's say say submodule A gets updated (a new commit ism adE), it should trigger a build where the main project code gets cloned. The submodule is not cloned.
  • How do I pull the latest changes from the submodule to the submodule directory after Jenkins clones the main project? Granted, the submodule directory will be at a detached head. How do I pull the latest changes to the submodule from the most recent commit (I cannot use git submodule update because that does not pull the latest changes to the submodule).

Basically, I want to give each submodule its own CI environment for testing, but each submodule is not a standalone application; they depend on the main project. So when a submodule gets updated, we need the main project updated with the latest code from that submodule without having the submodule cloned, the code from the submodule must be pulled. I don't want to set the polling on the main project. Jenkins should be checking the submodule each time to check if there is a new commit

liberforce
  • 11,189
  • 37
  • 48
James Umeris
  • 599
  • 2
  • 7
  • 15

1 Answers1

0

I would recommend one Jenkins job monitoring the parent repo.

By default, it doesn't clone the submodules if you don't enable Job Configuration -> Section Source Code Management, Git -> Advanced Button (under Branches to build) -> Recursively update submodules.
It will just monitor a clone of the parent repo, to fetch the latest commits at regular interval, simply by enabling Poll SCM, not by setting specifying a schedule: see "Automatically triggering a Jenkins build on Git commit".

If a submodule is updated, that means the parent repo will change as well.
When a submodule changes, a new parent repo SHA1 will be created and pushed as well, recording a gitlink (a special entry in the index). That gitlink references the new SHA1 of the submodule.

That means, each time the parent repo changes, the jenkins job needs to do a:

git diff --name-only --diff-filter=M ${revision} HEAD

If the M (modified) list include the right submodule for that job, then (using a Parameterized Trigger Plugin), trigger the right CI job.

The right CI job (one per submodule) will also monitor the main parent repo, will also not clone the submodules by default, except for the right one.
Its first step should follow "git submodule update specific submodule only"

git submodule update --init -- <specific relative path to submodule>

The rest of the job can build/test that specific submodule.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This won't work. I need it so that when the Submodule is updated it clones the Main project. But I don't want it to poll the main project only the submodule project – James Umeris Nov 15 '15 at 21:22
  • @JamesUmeris The issue is; the submodule wouldn't know what version (what SHA1) of the Main project to clone. Only the main project knows about the submodule, not the reverse. – VonC Nov 15 '15 at 21:28
  • No so I need it so that when the submodule gets updated it forces a clone of the main project. Clones the latest commit on master for the main project. But I don't want the submodule to be cloned – James Umeris Nov 15 '15 at 21:29
  • The polling has to be on the submodule not the main project – James Umeris Nov 15 '15 at 21:30
  • @JamesUmeris That I understood. You can try and setup a job with the submodule url to monitor, and have as a first step a clone of the main repo elsewhere. I suppose you would need a symlink between that checked out parent repo and the cloned submodule your monitored. – VonC Nov 15 '15 at 21:35
  • How do I prevent the main repo from being cloned on each commit to the main repo. I just need it cloned on each commit to the submodule. – James Umeris Nov 15 '15 at 21:36
  • @JamesUmeris As I said, a job monitoring the url of a submodule will never clone the main repo, since a submodule does not know anything about being referenced by said main repo. – VonC Nov 15 '15 at 21:47