Building a Continuous Integration Environment for Sitecore Part 1 – Teamcity

A unique opportunity has arisen for me. I have been tasked with building a fully automated build and deployment solution for Sitecore. So I have documented everything that I have done and will be presenting everything that I have done in a series of posts.

Part 1 – this post
Part 2 – Setting up OctopusDeploy
Part 3 – Setting up SQL Server for Sitecore
Part 4 – IIS
Part 5 – Octopus Environment and Deployment Configuration
Part 6 – TeamCity Project
Part 7 – OctopusDeploy Project
Part 8 – Sitecore Item Synchronization using Unicorn
Part 9 – Displaying Build number on Sitecore Home Page & Tagging Git
Part 10 – config transformations using Octopus Deploy
Part 11 – Deploying to a Sitecore Multi-Instance Configuration

For this I have been using the following tools:

I wont be listing everything in this post I will be breaking it down. First I will be detailing my first steps in setting up TeamCity

Assumptions

So a few assumptions. I have not listed every tool / application that I am using. I am using git Stash from Atlassian, but any git or other distributed source control system should work. I have not used Microsoft’s TFS so I have no idea if what I have done will work with a centralized source control repository.

All the servers are running Windows Server 2012 R2.All the servers are stand alone, and are not part of a domain. All servers have C and D drives.

Everything that is documented here and on subsequent posts are based on freshly installed Windows Servers.

Note

At least one Local Administrator account should be created so that you are not using the default Administrator account that is created during installation. However by default, the Local Security Policy for Windows Servers is to have passwords expiring every 42 days. As want to create accounts that do not have an expiring password, this will need to be disabled. The accepted default is to disable password expiration from the Local Security Policy

From Start Menu Run “Local Security Policy”

teamcity_lsp_1

Navigate to Account Policies | Password Policy. Double click “Maximum password age” and set the value to 0.

teamcity_lsp_2

Getting Started

Before starting download the following software. It will be used during this setup

Create the following drives as they will be needed later

  • D:\SQLBackup
  • D:\SQLData
  • D:\TeamCity
  • D:\TeamCity\Data
  • D:\TeamCity\Data\lib
  • D:\TeamCity\Data\lib\jdbc

Environment Setup

In preparation for Teamcity, several environment settings need to be added to the path. From Control Panel select System.

tc_env1

Select Advanced System Settings, and select the Advanced tab.

tc_env2

Finally click on Environment Variables

Set variable name to TEAMCITY_SERVER_OPTS
Set Variable value to -Djava.library.path=D:\TeamCity\Data\lib\

tc_env3

System Accounts

As I wanted to run TeamCity under a seperate administrator account the first step is to create a new User Account. From Control Panel select User Accounts | Manage another Account

teamcity_manageaccount1

Click “Add a user account”

teamcity_manageaccount2

You can pick whatever name you want, but I decided on TeamCity-Admin.
For the password, I used https://www.passwordgenerator.com to generate a strong password.

Once the account has been created, click on “Change the account type”

tc_acc3

And select Administrator

tc_acc4

Finally click Change Account Type

SQL Server

For this, I am going to be using SQL Server Express. What version you eventually end up using should have no impact on TeamCity

From the software downloaded, run SQLEXPRWT_x64_ENU.exe

tc_sql1

Select New SQL Server stand-alone installation or add features to an existing installation

tc_sql2

Accept the license terms and click Next

tc_sql3

Accept default to include SQL Server product updates

tc_sql4

Let the setup files be installed

tc_sql5

For Feature Selection leave as default
Click Next

tc_sql6

Leave instance Configuration with default options.
Click Next

tc_sql7

Change the SQL Server Browser to Automatic Startup Type
Teamcity requires a case sensitive collation. Switch to the Collation tab

tc_sql08

Click Customize
Ensure Case Sensitive is clicked

tc_sql09

tc_sql10

From the Server Configuration tab, click Next

tc_sql11

I prefer mixed mode instead of only Windows authentication mode.
Generate a secure random password to be assigned to the SA account

Click the Add button as want to add the TeamCity admin account created earlier as an administrator account

tc_sql12

tc_sql13

Switch to the Data Directories tab.

All the data directories will be created on the D Drive. I prefer to use a folder called SQLData for the data files and SQLBackup for all backup files.

tc_sql14

Set Data root dictionary, User database directory, User database log directory, Temp DB directory, and Temp DB Log directory to D:\SQLData
Set Backup Directory to D:\SQLBackup

No changes are necessary on the User Instances tab

tc_sql15

No changes are necessary on the FILESTREAM tab

tc_sql16

Click Next

tc_sql17

For Error reporting, leave unchecked and click Next

Now wait for SQL Server to be installed

tc_sql18

tc_sql19

Click Close to complete the SQL Server installation

Now need to create the Teamcity Database, and default SQL user for Teamcity

Run SQL Management Studio

Log in using either Windows Authentication,

tc_sql20

or using the SA account

tc_sql21

Run the following SQL script to create the database that Teamcity will use. Again I have defaulted the locations to the default of D:\SQLData.

CREATE DATABASE [Teamcity] 
 CONTAINMENT = NONE
 ON  PRIMARY 
( 
    NAME = N'Teamcity', 
    FILENAME = N'D:\SQLData\Teamcity.mdf' , 
    SIZE = 256000KB , 
    FILEGROWTH = 51200KB )
 LOG ON 
( 
    NAME = N'Teamcity_log', 
    FILENAME = N'D:\SQLData\Teamcity.ldf' , 
    SIZE = 102400KB , 
    FILEGROWTH = 10240KB )
 COLLATE Latin1_General_CS_AS
GO

Run this script to create user

USE [master]
GO
CREATE LOGIN [teamcity] WITH PASSWORD=N'teamcity', DEFAULT_DATABASE=[Teamcity], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
ALTER SERVER ROLE [sysadmin] ADD MEMBER [teamcity]
GO

Final SQL Server step is to configure SQL.

Run SQL Server Configuration Manager

Select SQL Server Network Configuration | Protocols from SQLExpress

tc_sql23

Update TCP/IP to “Enabled”

Select SQL Server Services.

tc_sql24

Ensure that the Start mode for SQL Server browser is Automatic. Start the service if it is not already running.

SQL Server is now in a state we can now start to install Teamcity

Teamcity

Pre Setup – SQL JDBC

Copy sqljdbc42.jar that was previously downloaded and extracted and copy to D:\TeamCity\Data\lib\jdbc
Copy sqljdbc_auth.dll that was previously downloaded and extracted and copy to C:\Windows\System32

Pre Setup – MS Build Tools

Run BuildTools_Full.exe that was downloaded previously

tc_msbuild1

tc_msbuild2

tc_msbuild3

Once the installation has completed, click Close button

I found an issue where not all the relevant build files are installed. Especially projects build using Visual Studio 2013 and Visual Studio 2015. So from a machine that has Visual Studio installed, copy across the following folfers and copy onto the same folder locations on the TeamCity server

  • C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web
  • C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications
  • C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web
  • C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications
  • C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\SSDT

TeamCity Installation

Run TeamcCity-9.1.6.exe

tc01

Click on Next

tc02

After reading the Licence Agreement, click I Agree button to accept the Licence Agreement.

tc03

Change the destination folder to D:\Teamcity, and click Next button

tc04

Select all the defaults and click Next button

tc05

Use the default port of 80 and click Next button

tc06

Accept the default Build Agent properties, and click Next button

tc07

Click ok to confirm that the properties where saved.

tc08

Select Run TeamCity under a User Account, and click Next button

tc09

Insert the credentials for the TeamCityAdmin account created previously, and click the Next button

tc10

For the Service Account, select Run under a user account. Click Next button to continue.

tc11

Enter the TeamCityAdmin account created previously,and click the next button to continue.

tc12

Ensure that tick the boxes to start both services, and click the next button

tc13

Allow TeamCity to install and click the Finish button to complete the installation

Teamcity First Run

Now that TeamCity has been installed, the first time you access the site, you will need to configure TeamCity for use. For all of the setup, I performed these steps while I had RDP’ed on the server. Therefore the address for everything is http://localhost.

As the images taken where from a live customer project, I have blanked out the customer and the project’s names in all images.

Within a new browser, run localhost/

tc14

Set the data directory to D:\TeamCity\Data, and click on the Proceed button

tc15

From the DB Connection, select MS SQL

tc16

Insert the credentials created earlier for SQL Server and click on the Proceed button

tc17
tc18

Read through and accept the Licence Agreement, and click Continue

Administrative User Accounts

tc19

Insert credentials for the default TeamCity administrator account. Make sure the password is strong enough. To keep things consistent, I have reused the same name as before.

tc20

You don’t want users of TeamCity to be accessing the site using the default Administrator account, so create a new user for daily use.

Select Administration | Users

tc21

Click on Create user account button

tc22

Enter all the user details and credentials and click on Create User button

Setup TeamCity as a NuGet Server

When the project is created, it will be generating a nuget file that will be supplied to Octopus, so TeamCity will need to be configured as a NuGet server

Select Administration | NuGet

tc23

Click on the Enable button

tc24

Click on the NuGet.exe tab

tc25

Click on Fetch NuGet

tc26

Select the latest version, at the time of this post it was 3.3.0 and click the Add button, and then wait until the agent has been updated

tc27

TeamCity Octopus Plug-In

Stop the TeamCity Server Service
Copy the file Octopus.TeamCity.zip to D:\TeamCity\Data\plugins (D:\TeamCity\Data\ is the TeamCity data directory )

Start the TeamCity Server service.
If you access TeamCity while it is still installing the plug-in you will get a maintenance page displayed

Next Steps

At this point TeamCity is ready for use, and a new project can be created. However will pause this for now as will need to install and configure the Octopus server as this is required for the project to be created.

Setting up and configurating the Octopus Deploy server will be discussed in Part 2.

This is continued in Building a Continuous Integration Environment for Sitecore Part 2 – Octopus Deploy

Advertisements

My musing about anything and everything

Tagged with: , , , , ,
Posted in CI, Continuous Integration, Octopus, Octopus Deploy, Sitecore, SQL Server, TeamCity, Unicorn
4 comments on “Building a Continuous Integration Environment for Sitecore Part 1 – Teamcity
  1. This is awesome.. more of a user guide than a blog post 🙂

  2. Jawad Sabra says:

    Great post Darren, Really helpful!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 12 other followers

%d bloggers like this: