Refactoring development

Ramblings from the trenches...

View on GitHub

15 years on and some teams don’t realise that CI is mandatory.

There’s several stages of evolution with TeamCity:

With ‘feature-branch’ support now in TeamCity we only need to copy our projects when we’re creating a new version of the build system, - not when we’re creating a new branch. TC can keep an eye on a range of branches and trigger a build on the right one. This removes the need for templating and keeps things simple again.


properties for trunk/branch, version checkout on agent

a project should be the level at which you branch at. I.e. you can have one with ‘trunk’ in the name.

Templates are good but you can’t template build dependencies so try to keep the dependencies within one TC project.

TeamCity

I’m assuming you’re fully bought into how awesome TeamCity is as a CI server. Have a look and see how your build scores against this list.

Maintenance

1. Thou shalt not select agents based on their name.

2. DRY: Templates are your friend.

3. Favour svn / package managers over agent installs

Speed

4. No more than 50 agents per server.

5. Keep it brief

6. Always checkout on the agent

Reliability

7. Always use the Free Disk Space build feature

8. Use custom errors.

9. Be hygienic.

Above all,

10. Don't live with red.

If you’ve got some great CI / TeamCity tips, please share!

Obligatory infographic:

TeamCity10Commandments

Agent Management

TeamCity is awesome, but there’s always room for improvement. Here’s a great trick to help you always select the right agents…

Agent-Selection

Once you’ve got a big build farm, agent selection has challenges. How many times have we realised the tests failed because that agent didn’t have a particular package installed on it?

One technique that works very well is to have a weekly task running on all compatible agents that scans the registry for all MSI packages installed and which version numbers they are.

This is easy enough to do in PowerShell:

Get-WmiObject -Class Win32_Product

Returns the installed set of products, with the Name and Version properties being on each product.

The secret is to then write this information to the build agent’s conf\build.properties file. The agent will then disconnect from the TeamCity cluster, and a minute later will re-connect with the appropriate settings.

One slight gotcha at the moment is to try not to have any version number as part of the property name as TeamCity can’t do wildcards on property names - only on the version field.

Run as Admin

Obviously it’s strongly recommended to not have your build chain need admin privileges to run, but for some builds it may be the only way. You could subset to build agents which have admin privileges by doing something like this:

([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")

(Again, if at all possible you can de-admin your build process that’s preferable!)

Hopefully you’ll find other good uses for this technique!