Continuous Integration with TeamCity and Git

martin's picture

VCS Root SettingsVCS Root Settings
Having recently migrated our Version Control System from SVN to Git, we needed to update our continuous integration (CI) environment to use Git. CruiseControl.NET works excellently with SVN, but does not support Git. A quick search revealed that a community plugin for Git (available from github, of course ;) ) has been created for JetBrains' TeamCity. I jumped at the opportunity to test this setup.

What you will need:
1 - TeamCity (v4.0.2 was the latest when going to press)
2 - Git TeamCity plugin (make sure to get this commit; apparently it has been merged into the master branch)
3 - maven - needed to compile the plugin (latest version is 2.0.10)

Steps:
1 - Install TeamCity: pretty straight-forward, see this post for guidance. (Tip: make sure that both the TeamCity Web Server and TeamCity Build Agent Service services have been started - it may be necessary to run the TeamCity Build Agent Service under a local user account and not the local System account - this can be configured during install of TeamCity or after).
2 - Build the Git plugin using maven. (Tip: make sure that your environment variables are set up correctly!).
3 - Install the Git plugin:

  • package the plugin by following the steps outlined in file pkg in the Git plugin folder: create a folder gitAgent/lib in the folder target, copy all the .jar files (should only be Git-vcs.jar) to this folder, and then zip gitAgent to gitAgent.zip
  • deploy the plugin by following the steps outlined in file deploy in the Git plugin folder: copy gitAgent.zip to \webapps\ROOT\update\plugins, and copy Git-vcs.jar to \webapps\ROOT\WEB-INF\lib

5 - Configure your TeamCity project: I will not explain the basics of configuring a project in TeamCity (the process is very well documented in the TeamCity documentation; also see this post), but will only give details on how to configure the VCS Root to use Git.

You first need to create and configure a VCS Root. You will note that "Git" appears in the Type of VCS drop-down, this indicates that the plugin has been installed successfully. You will also need to configure the VCS Settings for your particular project; make sure to select Automatically on agent (if supported by VCS roots) from the VCS Checkout mode drop-down (see the screenshots for details).

That's it! Do a test build run, and witness the magic.

UPDATE 2009/04/07: As Peter correctly points out, you need git installed on the build machine; I used 1.6.1-preview20081227 (msysgit). If not using the default git install path (i.e. C:\Program Files\Git or C:\Program Files (x86)\Git), make sure to update \src\main\java\org\hivedb\teamcity\plugin\GitConfiguration.java at line 87.

Windows Vista Gadget for TeamCity

You can find it here TeamCity Vista Sidebar Gadget

Thanks for the great tutorial

Thanks for the great tutorial man. I was searching for community plugin for Git for quite a long time. It was a real riddle to find this one, but you have helped me a lot. Moreover your blog always helps me to solve some difficult questions. I will download Teamcity right now and try to isntall Git teamcity plugin. Thanks one more time friend.

Sincerely,

Matt Irvin from software application development

CC.net git support

A git plugin for CC.net has been published in April.

RE: Problems with VCS Connection

Oh; fixed it. Submitted a patch to Jacob's github.com version of the plugin. The path to git, on the x64 platform, was lacking a git part :-)

RE: Problems with VCS Connection

Sorry; forgot about this since I changed jobs. I had msysgit installed, but the path differed in case. Does Java's file handling care about this?

Since then, I've successfully used JetBrains' own git plugin.

TeamCity now have an official

TeamCity now have an official plugin http://www.jetbrains.net/confluence/display/TW/Git (requires latest EAP and it will work with the next release)

re: 'Problems with VCS Connection'

Further investigation yields a more useful log [1] with an entry in it:
Unable to infer path to Git executable
out of /src/main/java/org/hivedb/teamcity/plugin/GitConfiguration.java:87

The method is looping through a bunch of paths to try to find a git executable. I guess it expects git to have been installed (I'm on Windows 2008 x64) via msysgit (I lean towards cygwin). I've done that, but the path differs in case - does Java care about that?

'Problems with VCS Connection'

I'm trying to get this working against TeamCity 4.0.2.8222.

I downloaded the plugin at version f964ec15798137ac4087da2bff46da73e540f21e from github. I installed maven and let it do its thing; it successfully built the plugin. I ran the pkg script successfully. I have deployed to TeamCity, and restarted Web and agents.

I've set up a new build config based against a Git VCS root. At this point, I have questions:
* What should go in the "Project Directory (Server)" input? A path within the repository...? What is this field for?
* Why do I get an exception on my build config at present:

java.lang.NullPointerException
« Hide details
java.lang.NullPointerException
at java.io.File.(File.java:194)
at org.hivedb.teamcity.plugin.GitConfiguration.createServerConfiguration(GitConfiguration.java:63)
at org.hivedb.teamcity.plugin.GitVcs.getCurrentVersion(GitVcs.java:33)
at jetbrains.buildServer.buildTriggers.vcs.VcsChangesLoader.updateCurrentVersionWhenLastDetectedIsNull(VcsChangesLoader.java:70)
at jetbrains.buildServer.buildTriggers.vcs.VcsChangesLoader.loadChanges(VcsChangesLoader.java:44)
at jetbrains.buildServer.vcs.impl.VcsManagerImpl.loadChanges(VcsManagerImpl.java:667)
at jetbrains.buildServer.serverSide.impl.auth.SecuredVcsManager.loadChanges(SecuredVcsManager.java:72)
at jetbrains.buildServer.serverSide.impl.VcsModificationChecker$1.run(VcsModificationChecker.java:2)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
at java.util.concurrent.FutureTask.run(FutureTask.java:123)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)

RE: Problems with VCS Connection

Hi Peter

* In the "Project Directory (Server)" I merely put my checkout directory (the local one on the build machine) - not sure what it is used for, but using the local checkout directory works for me.

* And yes, you do need git installed (I didn't mention it in my original post!), I am using 1.6.1-preview20081227 (msysgit). If your paths differ, try adding your path to /src/main/java/org/hivedb/teamcity/plugin/GitConfiguration.java at line 87.

Good luck! Let me know if you get it to work!

awesome stuff here guys,

awesome stuff here guys, thanks for the support on all of it!
Tony,
unsecured personal loans

Just wanted to add real fast

A note of thanks to the author for his generous contribution to the site. Cheers mate!
legal jobs

re: I have tried these

Is Git not appearing in the Type of VCS drop-down? Make sure that the plugin has been built and deployed correctly (steps 1 and 2). It may also be worthwhile to restart the TeamCity Build Agent Service and TeamCity Web Server services after you have deployed the plugin.

I think it might have

I think it might have something to do with the version of TeamCity I am using. I have 4.1 EAP because I need the NAnt configuration for mono which isn't supported in 4.0.2.

I have tried these

I have tried these instructions and its not appearing. is there anything more specific that should be done?