Displaying Build number on Sitecore Home Page & Tagging Git

You know the saying that you never stop learning.

I have decided to make this part 9 of the series of post that I am doing about building a Continuous Integration Environment using Sitecore, TeamCity, Octopus Deploy, and Unicorn. Was debating if this was relevant to that series, but as I am making changes to TeamCity and how the final solution is presented, it makes the cut.

Part 1 – Setting Up TeamCity
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 – This post
Part 10 – config transformations using Octopus Deploy
Part 11 – Deploying to a Sitecore Multi-Instance Configuration

By pure accident I came across a Sitecore Pipeline that will allow you to print your own text on the login screen to the Sitecore portal, the GetAboutInformation Pipeline

This is already well documented on several sites:

So I wont be spending much time on how its build, except to show you my, very basic, pipeline.

using Sitecore.Pipelines.GetAboutInformation;
using System.Reflection;

namespace MyProject.Sitecore.Pipeline
    public class AddBuildVersion
        public void SetLoginPageText(GetAboutInformationArgs args)
            args.LoginPageText = CurrentBuildInformationHtml();

        public void SetAboutText(GetAboutInformationArgs args)
            args.AboutText = CurrentBuildInformationHtml();

        private string CurrentBuildInformationHtml()
            return string.Format("<b>Website Build:</b> {0}", Assembly.GetExecutingAssembly().GetName().Version);

Now I initially tried using the new C# 6 style of string interpolation

$"<b>Website Build:</b> {Assembly.GetExecutingAssembly().GetName().Version}";

But unless you upgrade the version of .net running first on TeamCity and on all IIS Servers you will get errors. So until I am using a version of Sitecore that uses .net 4.6 instead of .net 4.5, I will be sticking with string.format. I know that it should not be an issue but a have a convention of only using the version of .net that the version of Sitecore I am using, is built on.

The patch file to include the pipeline within Sitecore.

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" >
        <processor type="MyProject.Sitecore.Pipeline.AddBuildVersion, MyProject" method="SetLoginPageText" />
        <processor type="MyProject.Sitecore.Pipeline.AddBuildVersion, MyProject" method="SetAboutText" />

Now getting TeamCity to use the build number as the version number is very simple.

Within the TeamCity project, add in a build feature, AssemblyInfo patcher

All you need to do is set Assembly version format to %system.build.number%.

Easy peasy. Now the version version number is displayed. However the challenge comes later when somebody raises a problem, and you have worked on the solution and have several changes that have not yet been deployed, how do you ensure that you get the correct version of the code from your repo.

Once again TeamCity can solve this.

These are the steps I used for Git. Things may be different if you are using a different VCS.

Within the TeamCity project, select Build Features


Click Add build feature


Select VCS Labeling from the drop down. Click Save


Select the VCS root to label, and specify the labelling pattern

Click Save

Now every time you do a build, the branch is labelled with the build number


Makes finding the correct commit to retrieve the code to review much easier


My musing about anything and everything

Tagged with: , ,
Posted in C#, Sitecore, TeamCity

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

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

Join 13 other subscribers
%d bloggers like this: