Setting Up Continuous Integration with TeamCity

by 

| September 14, 2016 | in

For one of my recent projects I needed to set up Continuous Integration from scratch on a server. Having never done this before I found myself assembling all the required components, installing them, and configuring them (and struggling now and then through some of the gotchas that came up).

To save anyone who may have to do this in the future a headache, I documented the entire process. And instead of just keeping that information within our walls, I’m also sharing my process with the world here on our blog.

Components Needed

Install JDBC Drivers

Most likely you will need JDBC drivers.

  1. Download the latest JDBC drivers from here.
  2. Unzip the downloaded package and copy the .jar file to C:\ProgramData\JetBrains\TeamCity\lib\jdbc (this is the default location and may be a hidden folder).

TeamCity Server Setup

I’m going to assume you can install Microsoft SQL Server 2016 Express, SQL Server Management Studio, and Build Tools without any help from me. Although, note your SQL Server instance name (we’ll need that later).

So let’s jump right to installing and configuring TeamCity.

  1. Run the TeamCity installer.
  2. After you click through a few installation windows, specify the desired port number through which you want TeamCity to communicate and click Next. Refer to these instructions if you want to change it later.
    ci_1
  3. The installation will continue with its configuration. This may take a while. When it’s complete, you are presented with a Configure Build Agent Properties box. Click Save.
  4. The Select Service Account for Server box displays. Specify the appropriate Domain, Username, and Password. These will typically be the credentials used to log into the server. Click Next.
    ci_2
    Note: You may be prompted for this information twice.
  5. Continue through the configuration boxes and click Finish.
  6. After configuration is complete, the TeamCity First Start page displays in a browser window. TeamCity recommends using Internet Explorer for this.
  7. Verify the Data Directory location and click Proceed.
    ci_3
  8. The Database Connection Setup page displays. Select “MS SQL Server” as the database type and, if necessary, specify the Database host[:port], Database Instance name, Database name, and Authentication method. Select “Windows authentication” as the Authentication method.
    Click Proceed.
    Note: If you will be using a remote database, refer to the TeamCity documentation.
    ci_4_alt
  9. If the Create Administrator Account page displays, proceed to step 22.
    If you receive either of these messages, proceed to step 10:
    The TCP/IP connection to the host localhost, port 1433 has failed. Error: “Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.”.

    SQL exception: The TCP/IP connection to the host localhost, port 1433 has failed. Error: “Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.”.
  10. Open the Computer Management window and enable your TCP/IP connection for SQL Server Network Configuration.
    ci_7
  11. Open the Component Services window and restart the SQL Server service.
    ci_9
  12. Return to the TeamCity Database Connection Setup page in your browser and click Proceed. This will verify that steps 10-11 worked. The following error message should display:
    SQL error when doing: Taking a connection from the data source: no sqljdbc_auth in java.library.path
  13. Unzip the JDBC driver and copy the sqljdbc_auth.dll file to the lib folder under the TeamCity install location (e.g., C:\TeamCity\lib).
  14. Open the System Properties box (Windows Control Panel -> System and Security -> System -> Advanced system settings), click the Advanced tab, and click Environment Variables.
  15. The Environment Variables box is displayed. Click New in the System Variables section.
  16. The New System Variable box is displayed. Specify the following values and click OK:
    Name: TEAMCITY_SERVER_OPTS
    Value: -Djava.library.path=c:\TeamCity\lib
    ci_9-2
  17. Launch SQL Server Express to create a TeamCity database and database user. Ensure that the database Collation is “SQL_Latin1_General_CP1_CS_AS”.
    ci_10
  18. Ensure the database user has db_owner role membership.
    ci_11
  19. Return to the Component Services window and restart the TeamCity service.
  20. Return to the TeamCity Database Connection Setup page in your browser and refresh the page.
  21. Click Proceed.
  22. The Create Administrator Account page displays. Specify a Username, and create and reenter a Password. Click Create Account.
    ci_13

TeamCity Project Setup

  1. Navigate to your TeamCity page in your browser of choice.
  2. Click New Project from the Projects menu.
  3. Enter a Name for the project and click Create.
    ci_14
  4. Click Edit Project Settings.
    ci_15
  5. Expand the Project Settings menu on the left and click VCS Roots. Then click Create VCS root.
    ci_16
  6. Complete all the fields, select the appropriate Authentication method, and click OK.
    Note: The VCS RootName is your main Github Repo or similar source control.
    ci_16_2
  7. Click General Settings in the menu on the left and click Create build configuration.
    ci_17_1
  8. Click Build Step in the Build Configuration Settings menu and click Add build step.
    ci_18
  9. Before you can run a build you may run into a “Team city unmet requirement: MSBuildTools12.0_x86_Path exists” message. This means you don’t have the appropriate build tools installed on the server. Download build tools and restart TeamCity and TeamCityAgent on the server. Alternatively, you can also copy the build tools from your dev machine into the appropriate location on your server.

Hopefully these steps will help get you through some of the gotchas that come with getting all these components set up for Continuous Integration.

author avatar
Chris Niemann Sr. Software Engineer
Chris joined Don’t Panic Labs right after he finished playing college basketball and has been learning from his colleagues about the depth of programming since. It turns out that there are a lot of things that college doesn’t teach you about what it means to be a good software engineer. Most days you will find him in the office, but he also likes to stay close to coffee shops when he is writing code.

Related posts