11

How to setup TeamCity trigger to start build on changes in git submodule?

Currently you have to update a submodule commit pointer to trigger a build in the main repository, so that TC will register a change in the main repository.

Update

The problem is the submodule should be always tracking a branch master. AFAIK this cannot be achieved through git itself. I just would like for the build to overcome git limitation in that matter.

Janusz Skonieczny
  • 17,642
  • 11
  • 55
  • 63

3 Answers3

6

This is not a neat solution but is achieves a goal to build a project with the tip of the submodule, and not needing to update submodule by hand. (A hook would probably do to)

Create a separate build configuration on with the submodule as the main repo, and setup a command line build step to clone a maste-repo, pull/update submodule and push the updated submodule pointer back to the master-repo.

rm -r master-repo
git clone git@github.com:xxx/master-repo.git
cd master-repo
git status
git submodule update --init 
git config -f .gitmodules submodule.submodule-repo.branch master
cd submodule-repo
git pull origin master
git status
cd ..
git add submodule-repo
git commit -m "sub module update"
git push origin master

I'm new to git so this probably can be optimized.

Janusz Skonieczny
  • 17,642
  • 11
  • 55
  • 63
1

It is not possible to do that as TeamCity (and git) cannot know that there is an update. Submodule entry in a repo just points to a commit.

What would be an update to it? There can be multiple branches and commits from this commit. Only you can decide where the submodule is to be updated to.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • How about [git submodule tracking latest](http://stackoverflow.com/questions/9189575/git-submodule-tracking-latest), isn't it supplying the branch information? – Janusz Skonieczny May 26 '14 at 19:12
0

I've just been looking at trying to achieve the same thing with TeamCity, but quickly concluded it doesn't make sense to be doing it. Your TeamCity build should be based on what's in your master repository, and, as you say, the way GIT submodules work means it's up to the master repository to update it's pointer to the new commit in the sub-repository, which will trigger a build.

Bottom line is, I don't want TeamCity building something that I can't recreate from source, i.e. cloning the master repository will not reflect what TeamCity actually built.

SteveChapman
  • 3,051
  • 1
  • 22
  • 37
  • 3
    Sorry, wasn't asking for a opinion, I'm rather looking to solve task at hand. – Janusz Skonieczny Jun 05 '14 at 10:23
  • 2
    Fair enough, but I was merely trying to validate the problem area. Have you tried setting up a second VCS root to the submodule and triggering from that? Just an idea. – SteveChapman Jun 05 '14 at 10:35
  • I dropped that idea, as there can be only one VCS trigger, but to be honest I did not check if having multiple VCS roots and one trigger can do the trick. I work on that. – Janusz Skonieczny Jun 05 '14 at 10:39