Installing TeamCity with MS SQL 2008

by Mikael Henriksson 19. June 2010 16:42

The first time I installed TeamCity it took me about a day to get everything in place (excluding setting up the build configurations). Second time I installed TeamCity on a real server it took me about 30 minutes including setting up all the build configurations. I didn’t really do any second time, I transferred the database.properties file and a backup to the server.

There are a few tricks to doing this right and I’ll walk you through them but first let’s establish a few things. The .BuildServer directory is where the magic happens, the TeamCity directory is where the web server and the BuildAgent installers and plugins are located. A BuildAgent can be installed on any remote machine, just make sure you have enough licenses to connect with the BuildServer.

.BuildServer directory is by default "C:\Users\UserName\.BuildServer" and will from now on be referred to as just .BuildServer

  1. Install TeamCity (no brainer)
  2. Install configure a database you want to use. The user you are using for teamcity must have dbo access to the database.
  3. Download the database driver from http://sourceforge.net/projects/jtds/files/
  4. Unzip "jtds-1.2.5-dist.zi"
  5. Copy "jtds-1.2.5.jar" to ".BuildServer\lib\jdbc\jtds-1.2.5.jar"
  6. Navigate to ".BuildServer\config" and create a new file called database.properties

Here is where I got lost for a while. The port for SQL Server needs to be specified and this is not done by default. Further it was really hard to find how to specify the instance name. This is how it should look when it’s correct (using an instance):

connectionUrl=jdbc:jtds:sqlserver://COMPUTERNAME:1433/DATABASENAME/instance=INSTANCENAME;
connectionProperties.user=teamcity
connectionProperties.password=teamcity

maxConnections=50
testOnBorrow=true

This led me up to the next problem saying java is not recognized function or program. After searching the internet for about an hour I gathered that I needed to add environment variables for java so I added JRE_HOME and JAVA_EXE but this didn’t do (pardon the language). There is a quick fix though. Inside "C:\TeamCity\bin" there is a file called "findJava.bat" inside here I just modified the second last statements. This is what my findJava looks like:

:: ---------------------------------------------------------------------
:: Searches for Java executable
:: ---------------------------------------------------------------------

SET JAVA_EXE=%JRE_HOME%\bin\java.exe
IF EXIST "%JAVA_EXE%" goto java_found

SET JAVA_EXE=%JAVA_HOME%\jre\bin\java.exe
IF EXIST "%JAVA_EXE%" goto java_found

SET JAVA_EXE=%JAVA_HOME%\bin\java.exe
IF EXIST "%JAVA_EXE%" goto java_found

SET JAVA_EXE=%TEAMCITY_HOME_DIR%\jre\bin\java.exe
IF EXIST "%JAVA_EXE%" goto java_found

:: ---------------------------------------------------------------------
:: No JAVA_HOME or JRE_HOME set and no bundled JRE found, trying to run java from the PATH
:: ---------------------------------------------------------------------
SET JAVA_EXE="C:\TeamCity\jre\bin\java.exe"

:java_found

Now your TeamCity build server should start working if you have configured your SQL Server instance correctly. I was missing adding to the instance that it should be listening to TCP Port 1433.

sql_server_config

And of course your windows firewall might need opening ports if the two are not located on the same machine.

Next I’ll tell you how to move this configuration to another machine should you ever have the need.

Tags: ,

Team City | Windows Server

blog comments powered by Disqus

About the author

Life architect specialized in programming