Skip to content

Instantly share code, notes, and snippets.

@andrewabest
Last active December 3, 2019 13:42
Show Gist options
  • Save andrewabest/36ce91dd7801977ec264cd8100a77929 to your computer and use it in GitHub Desktop.
Save andrewabest/36ce91dd7801977ec264cd8100a77929 to your computer and use it in GitHub Desktop.
Setting up GitVersion in TeamCity

Project Stuff

Firstly - we will use the CommandLine utility to do our versioning - this lets us check the versioning behaviour locally before pushing, which can be super handy!

Install-Package GitVersion.CommandLine

Then, configure gitversion

.\packages\GitVersion.CommandLine.3.5.2\tools\GitVersion.exe init

Select the options that are applicable to your situation - in our case we are using GitFlow and Continuous Deployment mode, which plays nicely with Octopus (https://gitversion.readthedocs.io/en/latest/more-info/incrementing-per-commit/)

Finally double check that you haven't accidentally ignored some of the files under the GitVersion folder in packages, namely the x86 and x64 folder contents, which some .gitignore's will ignore by default

TeamCity Stuff

  1. In your (or appropriate scope)
  • Define a Configuration Parameter named GitVersion.NuGetVersion - GitVersion will update this with the SemVer once it is calculated
  • Define an Environmental Variabled named env.GITVERSION_REMOTE_USERNAME - Used by GitVersion to talk to your git repo
  • Define an Environmental Variable named env.GITVERSION_REMOTE_PASSWORD - Used by GitVersion to talk to your git repo
  1. In your Build Configuration's VCS Root, you need to set up your build's VCS checkout mode to be "Automatically on agent" - this means that:
  • You need to install git on your build agents
  • You must use http or https in your VCS root, not SSH (https can be a PITA to set up in this case)

2a) Configure the VCS Root to build tags

  1. Set your Build Configuration's build number format to {0}

  2. Add a new build step to your Build Configuration in position 0 named GitVersion - this will take care of updating your assemblyInfo and updating variables in TC

  • Make it a command line step
  • Executable with parameters packages\GitVersion.CommandLine.3.5.2\tools\GitVersion.exe
  • Parameters /output buildserver /updateassemblyinfo true
  1. (If using Octopus) Update the OctoPack Package Version variable in your VS Build step to %GitVersion.NuGetVersion%

  2. 1.0.0-winning0001

NOTE: The VCS Tagging build feature may upset your CI when your VCS is set to build tags (which it should be) - as when TC tags your build, it will then build the tag, which will trigger a build of the same semver - and if this creates an Octo release, the release number will already be taken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment