Part II: Setting Up Our Build Server With TeamCity
This is the second part of a series dedicated to Continuous Integration with .NET. In the first part we managed to install and configure a source control repository with Subversion. Now we’re going to learn how to install and configure TeamCity as our CI build server. At the moment of this writing, version 3.1 is the latest release version of TeamCity. I’ll make sure to update the present content to reflect new changes in installing and configuring future releases of the product if necessary.
I recommend that TeamCity be installed in a separate (physical or virtual) machine than the one where Subversion is installed because if you need to update TeamCity, to apply a service pack to the operating system or to upgrade the .NET Framework, the machine will have to be restarted and this could cause some major productivity downtime to the team because the repository will be unavailable until the machine is back online.
A last note to consider before proceeding is that I’m also going to show you how to setup MySQL to act as the storage engine for TeamCity. You’ll be happy to know that configuring MySQL as the storage engine for TeamCity is much easier and simple to do in TeamCity v3.1 than in its previous versions.
If you’re already using a previous version of TeamCity and you want to upgrade to the current version, I strongly recommend you to read JetBrains’ article on “Migrating to an External Database” to know how to properly backup your current data before upgrading to a newer version.
=> Step1. Make sure that you have installed the Microsoft .NET SDK with the latest service packs in the machine where TeamCity will be installed. If necessary, install and configure Internet Information Services (IIS) too.
=> Step 2. Download TeamCity from JetBrains’ website. You can read this post for more information between both the Professional Edition and the Enterprise Edition.
=> Step 3. Install TeamCity as you would install any typical Windows application (NEXT->NEXT->…->FINISH). Here are some tips that might assist you during the installation:
- Make sure you install both the Build Agent Windows Service and the TeamCity Server Windows Service (as shown in figure 1). The build agent is responsible to take a build script and running the necessary steps to perform a build. It’ll send the results back to the server. The server is going to notify you of the build results. As described in this series’ preface, you can install multiple agents for one TeamCity server, but depending on the license you have, you might be limited to a number of agents a server can be attached to. Refer to TeamCity’s documentation for more information.
Figure 1. Install both the Build Agent Windows Service and the Server Windows Service
-
Take note where the build server configuration has been installed (by default it is located under C:\Documents and Settings\Administrator\.BuildServer), I’ll refer to this location as the TeamCity data directory.
-
Make sure you specify a server port that isn’t in conflict with another port. For instance, IIS uses port 80 by default, so you might not be able to use the same one unless you shut down IIS or change its default port. I tend to use port 8080 for TeamCity server (as shown in Figure 2).
Figure 2. Specify an available port for TeamCity server
-
Feel free to take a snapshot of the next window (”Configure Build Agent Properties”) and save it somewhere for information purposes. After clicking on the ‘Save’ button, the following window (”TeamCity Build Agent Properties”) will popup. Take note of the location where the build agent’s properties file will be saved at for future reference.
Figure 3. Build Agent’s Configuration window
-
Make sure you tell the installer to start the build agent and build server Windows services:
Figure 4. Start both the Build Agent service and the TeamCity Server service
=> Step 4. Create a new system environment variable. The name of the variable should be TEAMCITY_HOME_DIR and its value should be the location where you have installed TeamCity (i.e., c:\TeamCity). Restart the machine at this point.
=> Step 5. Fire up a browser and connect to TeamCity (i.e., http://localhost:8080). Accept the EULA at the bottom of the screen and create a new administrator account. If you click on the Administration tab (upper right side of the screen), you’ll notice the following message:
=> Step 6. In this step and the next one, we’re actually going to install and configure MySQL as a storage engine for TeamCity. The configuration settings should be appropriate for most situations. Feel free to configure MySQL as needed for your own business/technical purposes.
=> Step 6.1. Download MySQL Community Edition from the following URL: http://dev.mysql.com/downloads/mysql/?rz=gdl#downloads (you don’t have to sign up in order to download MySQL. There’s actually a link underneath the registration page that says “No thanks, just take me to the downloads!”…They’re so polite.) In this article, I’m assuming you’re downloading the MySQL Essentials 5.0.51a Win32 installer. The following steps describe how I’ve configured MySQL to act as a storage engine for TeamCity.
=> Step 6.2. Click ‘Next’ on the ‘Welcome’ window
=> Step 6.3. Make sure you selected ‘Custom‘ as the setup type, then click on ‘Next’.
=> Step 6.4. Verify that both the MySQL Server and Client Programs will be installed. Click on ‘Next’ to continue.
=> Step 6.5. Click on ‘Install’ to continue with the installation. Feel free to surf the web (or my blog *hint*) while it’s installing…
=> Step 6.6. After finishing installing, you’ll see a bluish window with the MySQL/dolphin logo. Just click on ‘Next’ until you see the “Configure the MySQL Server now” window. Click on ‘Finish’, then on ‘Next’ to begin the configuration.
=> Step 6.7. Select the ‘Detailed Configuration‘ as the configuration type, then click on ‘Next’.
=> Step 6.8. Select the ‘Server Machine‘ as the server type, then click on ‘Next’.
=> Step 6.9. Select the ‘Transactional Database Only‘ as the database usage, then click on ‘Next’.
=> Step 6.10. Select a drive and directory where the InnoDB tablespace should be placed, then click on ‘Next’. In my case, I simply decided to install it under ‘c:\MySQL InnoDB Datafiles\‘.
=> Step 6.11. Select the ‘Decision Support (DSS)/OLAP‘ as the concurrent connections setting, then click on ‘Next’.
=> Step 6.12. Select the ‘Enable TCP/IP Networking‘ option and specify the port number. I kept the default 3306 port. Make sure to tick the “Add firewall exception for this port“ checkbox and also select the ‘Enable Strict Mode‘ as the SQL mode. Then click on ‘Next’.
=> Step 6.13. Select the ‘Best Support For Multilingualism‘ as the default character set (UTF8), then click on ‘Next’.
=> Step 6.14. Select ‘Install As Windows Service‘, provide a service name (I left the one provided by default), select ‘Launch the MySQL Server automatically‘ and also select ‘Include Bin Directory in Windows PATH‘. Click on ‘Next’ to continue.
=> Step 6.15. Type a password for the root account. Don’t allow root access from a remote machine on this account. You don’t need to create an anonymous account. Remember your password as you will need to enter it later. Click on ‘Next’ to continue.
=> Step 6.16. Click on ‘Execute’ to start the configuration. Once the configuration has completed, click on ‘Finish’.
=> Step 6.17. Take a break…seriously…surf the Web, drink some coffee, go to the bathroom…We’re almost done. The next steps are about configuring MySQL to act as the storage engine for TeamCity.
=> Step 7. Ok, now we’re done with installing and configuring MySQL. It’s time to configure the MySQL as the storage engine for TeamCity.
=> Step 7.1. Shut down (stop) the TeamCity server Windows service. You can do this via the Service Controller command or the Windows Services window. The name of the service should be TeamCity.
=> Step 7.2. Download the MySQL JDBC driver (ZIP) from the following URL: http://dev.mysql.com/downloads/connector/j/ and extract the JAR file (mysql-connector-java-5.1.6-bin.jar) to <TeamCity home>\webapps\ROOT\WEB-INF\lib. In my case, this would be C:\TeamCity\webapps\ROOT\WEB-INF\lib.
=> Step 7.3. Now we’re going to create a database that will be used by TeamCity for storing various data (feel free to refer to the following URL to set up an external database with MySQL: http://www.jetbrains.net/confluence/display/TCD3/Setting+up+an+External+Database#SettingupanExternalDatabase-settingUpMySql)
=> Step 7.4. Fire up a MySQL Command Line Client (Start menu -> All Programs -> MySQL -> MySQL Server 5.0), type in the root password from Step 6.15 and hit Enter to continue.
=> Step 7.5. Type the following command to create the database:
CREATE DATABASE TeamCityDB DEFAULT CHARACTER SET utf8; |
and then hit Enter to execute the command. You have now created a database named TeamCityDB which will be used by TeamCity. DO NOT CREATE ANY TABLES AT THIS POINT!
=> Step 7.6. If you don’t want the root account to control the TeamCityDB database, feel free to create a user and grant that user the necessary permissions to modify the database. See MySQL’s documentation for more information on how to create database users.
=> Step 7.7. In the TeamCity data directory (i.e., C:\Documents and Settings\Brian\.BuildServer\config) rename database.mysql.properties file to database.properties and specify the required settings in this file:
connectionUrl=jdbc:mysql://<host>/<database name> connectionProperties.user=<user> connectionProperties.password=<password> |
In our case, the <host> is the name of the machine where MySQL is installed, i.e. localhost. Since MySQL will only be used by TeamCity, I didn’t bother creating a dedicated user. Therefore, I’m using the root’s account as the database user for TeamCityDB. This might not be appropriate for your situation. Figure 5 shows you what I’ve entered for that section:
Figure 5. Fill in the necessary information for the MySQL database (database.properties)
=> Step 7.8. Edit the <TeamCity home>\bin\dbMigration.properties file, entering correct values for the source and target database. Ensure all the properties are supplied and only the necessary lines are uncommented (single-line comments are designated by # character). The following figure shows you what needs to be modified in the red boxes (the second red box should have the same values as entered in Step 7.7):
Figure 6. Fill in the necessary data in the dbMigration.properties file
=> Step 7.9. Cool! Now we’re ready to run the migration tool. FYI, configuring MySQL to act as the storage engine for TeamCity is so much easier to do in this version of TeamCity (v3.1) than the previous versions. All you have to do is execute the following command in a DOS command prompt (make sure the current directory is <TeamCity home>\bin) and the tool will take care of the rest…I love it!
c:\TeamCity\bin\migrateDB.bat migrate |
You’ll have to specify the TeamCity data directory. If you hit Enter, the tool will use the shown directory as its value. The migration tool really simplifies our lives for configuring MySQL with TeamCity. Excellent job, JetBrains! The following figure shows you the output of the operation.
Figure 7. This is the output generated after running the migration tool
=> Step 7.10. You’re done! Start the TeamCity server Windows service and log in your TeamCity account.
In this article, I have presented the necessary steps to install TeamCity as a CI build server and install/configure MySQL to act as the storage engine for TeamCity. In the next, we’ll actually get our hands dirty and integrate a .NET application with a few build configurations. Stay tuned!
By the way, if your curious to know, the output generated in Figure 7 shows you ALL the tables created in the TeamCityDB database. For instance, if you do a SELECT * FROM users; on the TeamCityDB, you will get all the TeamCity user accounts with their passwords in clear text (as shown in Figure 8)! This is a major security flaw since passwords should be encrypted in some way…else what’s the use? I hope that JetBrains will fix this issue someday.
Figure 8. You can clearly see the Administrator’s password ‘admin’ in clear text in the ‘users’ table
Similar posts you might be interested in reading:
- Setting Up a Continuous Integration Environment (Preface)
- Part I: Beginning the CI Journey with Subversion
- Jay Flowers on Continuous Integration (MSDN Magazine - March 2008)
- Better Modelling with the Visual Studio Class Designer
- This Week’s Geek Links (May 16th, 2008)
- Book Review #7: "The Dip: A Little Book That Teaches You When to Quit (and When to Stick)"
- TeamCity 3.1 Released
March 24th, 2008 at 7:20 pm
I’m interested in your rationale for choosing TeamCity over other continuous system. Any comment?
March 25th, 2008 at 5:58 pm
Ken,
I opted for TeamCity for a couple of reasons:
1. It’s the product we chose over CC.NET for implementing a CI environment at a client’s organization. We basically decided to go for it because of the many advantages it offered (we’re talking about version 2.11 from 2007) such as distributed build agents, allowing developers to perform a ‘personal build’ (or a delayed commit), seamless integration to Visual Studio via a plugin (which is a major plus for developers), easy configuration and installation, etc. The product being written in Java (portability) also provides an excellent business strategy because the organization can decide to install the build agents on machines running Linux (which totally rocks for Java applications, but much less for .NET unless we’re ready to use MONO).
2. I wanted to write a series of articles about CI using TeamCity, because there’s already a tremendous amount of information online on how to install and configure CC.NET. Furthermore, since version 3.x of TeamCity is now free (Professional Edition), there’s much less confusion whether to use an open source version of a CI server or a commercial/free one.
3. The support provided by JetBrains is excellent. Anyone can ask a new feature in their issues tracking software and if many people request/vote on the same feature, there’s a big chance that it’ll get implemented in the next version.
I hope I answered your question.
Regards,
Brian
March 30th, 2008 at 3:56 am
I would like to share my experience with TeamCity.
Ken, I’m from the SONIA project (sonia.etsmtl.ca) at ETS(École de technologie supérieure). We learn about TeamCity when Brian first mentioned it in a post on March 17. We had try CruiseControl before but we did not like it, the interface was not very easy to understand and the configuration were a pain for us. We then decided to give a chance to TeamCity, we installed it on a Linux server. We had some specific requirement, we use 2 programming language inside the project, C++ and Java. The C++ part need some specific library so, what we did was to setup a buildagent directly on the “specific” development machine and another one that we let on the server so he could do the Java part. We simply added an environment variable so we could configure one of the buildagent to work only if it was set. This was soo simple !!
We are getting mail when the build failed and also setup our build script to make some artifact. TeamCity was easily configure to create the artifact and then put them to be downloaded directly from the interface.
If any body need more feed back about the linux installation, I can give them.
LaMs
April 17th, 2008 at 12:44 am
Sweet! Got my CI environment up and running in no time. Now I have to configure the build agents, etc…
My TeamCity installation did not include the dbMigration.properties file - however, everything configured fine.
!! Special note to those installing MySQL on Vista or Server 2008:
There is a bug in MySQL 5.0.51a that prevents the MySQL config from executing on vista/2008 (ref bugs.mysql.com/bug.php?id=30823).
I applied the following hack with success (suggested by Gunnar Gudvardarson in the bug report’s thread):
To install MySQL Server 5.0.51a in Vista
1. Use mysql-essential-5.0.51a-win32.msi
2. Download and run Resource Hacker http://www.angusj.com/resourcehacker/
3. Open …\MySQL Server 5.0\bin\MySQLInstanceConfig.exe with Resource Hacker
4. Navigate to 24\1\1033
5. Delete all text in the window
6. Press “Compile script”
7. Exit Resource Hacker and save the result (overwrite the initial
MySQLInstanceConfig.exe)
8. Now MySQLInstanceConfig.exe should start normally.
EH