Following on from my posts Continuous Delivery with Sitecore Part 1 – TeamCity Setup and Continuous Delivery with Sitecore Part 2 – Octopus Deploy Setup, I’ve added another step to achieve Semantic Versioning (SemVer) in my deployment pipeline, as we are already using GitFlow  for branching we only had some configuration changes to make.

I’ve added GitVersion to our release process, they claim

Versioning when using git, solved. GitVersion looks at your git history and works out the semantic version (semver.org) of the commit being built.

This enables my release numbers to be automatically generated using semver.org and this number can be used to version assemblies,  add source control tags and for any NuGet packages or other artifacts your build process generates.

Setup

  • Add a reference to GitVersionTask via Nuget to your solution
    
    Install-Package GitVersionTask -Version 3.6.3
    
    
  • You will need to generate a GitVersionConfig.yaml config file and add it to the root of your solution mine is below, GitVersion will then use this configuration and your repository history to work out the next build number, for more on the configuration file see the documentation – https://gitversion.readthedocs.io/en/latest/configuration/

I use Team City and Octopus Deploy for build and deployment currently but GitVersion Supports a wide range of build tools.

GitVersion Build Server Support

GitVersion has support for quite a few build servers out of the box. Currently we support:

Setup for TeamCity

  • Create new System Parameters to act as placeholders for the values generated by GitVersion, I have created system.GitVersion.FullSemVer, system.GitVersion.NuGetVersion and system.GitVersion.SemVer. You can view the Variables generated by GitVersion here – https://gitversion.readthedocs.io/en/latest/more-info/variables/

teamcityparameters

 

Set the Build number format of your Team City Build to %system.GitVersion.SemVer%  the placeholder we previously created.

 

 

buildnumberformat

 

 

Add a new Command Line step to your build, after your NuGet Packages have been restored and before your Build and OctoPack step. The Command Executable is GitVersion and the command parameters are . /updateAssemblyInfo /output buildserver

 

 

teamcitystep

 

Add the new system variable in the 

 

 

octopackversion

 

http://docs.octopusdeploy.com/display/OD/TeamCity#TeamCity-InstallPluginInstallingtheplugin

On your Create Release and Develop Release steps when using the Octopus TeamCity plugin set the Release number field to %system.GitVersion.NuGetVersion%

 

 

octopuscreatereleasebuildsnumber

 

That is all the setup required, when you next Run a new build on TeamCity you should see the results:-

Results

TeamCity builds with SemVer build numbers.

teamcitybuilds

TDS packages with NuGetVersion version generated by GitVersion

tdspacakges

Octopus Deploy release numbers using NuGetVersion

octopusbuilds

Assemblies stamped with the same SemVer release number.

assembly

Leave a Reply

Your email address will not be published. Required fields are marked *