This is the second post in my two post mini series where I try to describe my development environment. I have already mentioned that I use TeamCity as my continuous integration and build system. In this post I will describe how to configure TeamCity to use SQL Server as a main configuration repository.
Installation of TeamCity
Run TeamCity installation to install the build server and build agent on your server. This will give you fully functional build system that is integrated with your development components. It will automatically (when configured appropriately) trigger build when a change is submitted into your VisualSVN Server repository. The build will use MSBuild to build all the artifacts of your project including running unit tests, generating source code documentation, etc. When finished the system will automatically label the source code after a successful build.
Currently all configuration is written into HSQLDB database.
Microsoft SQL Server as a configuration repository
Assumtions: You have 64-bit operating system and you have installed TeamCity into C:\Program Files (x86)\JetBrains\TeamCity and your build server configuration is at C:\BuildServer folder.
JDBC driver
TeamCity is written in Java and therefore we need Java drivers for Microsoft SQL Server. Download and install JDBC driver from Microsoft SQL Server JDBC Driver page. Copy sqljdbc.jar and auth/x64/sqljdbc_auth.dll into C:\Program Files (x86)\JetBrains\TeamCity\webapps\ROOT\WEB-INF\lib.
Configure SQL Server for JDBC driver
Open SQL Server Configuration Manager and make sure that SQL Server (MSSQLSERVER) is up and running and that TCP/IP protocol is enabled (using port 1433).
Create SQL Server database
Open SQL Server Management Studio and add a new Login named teamcity. In this example I will use SQL Server authentication with password teamcity (because I chose such a simple password I need to uncheck Enforce password policy).
Create a new database named TeamCity and add teamcity user to the newly created database as db_owner.
Configure TeamCity migration tool
Edit C:\Program Files (x86)\JetBrains\TeamCity\bin\dbMigration.properties file and make sure that sourceURL is set correctly:
sourceURL=jdbc:hsqldb:file:C:/BuildServer/system/buildserver
Now we need to add target configuration for the migration. This is where we add information about our newly created SQL Server database:
# MSSQL 2008 via JDBC
targetDriver=com.microsoft.sqlserver.jdbc.SQLServerDriver targetURL=jdbc:sqlserver://dpokluda:1433;database=TeamCity;
targetUser=teamcity
targetPassword=teamcity
Configuration migration
To execute the migration follow these steps. Start PowerShell (or any other shell but you will need to change the bellow mentioned steps).
Add Java to your Path variable so that migration tool can run it. This step is only necessary when you don’t have Java installed on your system and you want to use the one that comes with TeamCity.
$env:Path += ";C:\Program Files (x86)\JetBrains\TeamCity\jre\bin"
Stop all TeamCity services.
stop-service TCBuildAgent
stop-service TeamCity
Navigate to TeamCity bin folder and start the migration.
cd "C:\Program Files\JetBrains\TeamCity\bin"
migrateDB.bat migrate
(It is fine to press just [Enter] key here since we have entered the full path into the dbMigration.properties file - otherwise enter C:/BuildServer path.)
Start TeamCity services.
start-service TCBuildAgent
start-service TeamCity
Verify functionality of the new repository
Navigate to your TeamCity web page and add a new user in TeamCity administration named Test.
Open TeamCity database in SQL Server Management Studio and you should see that there is a new user named Test in users table:
SELECT TOP 10 * FROM [TeamCity].[dbo].[users]
For more information see the following resources:
Coding
teamcity, sqlserver, powershell, dotnet