GitVersion tool: Semantic Versioning 2.0 in Azure DevOps

Semantic Versioning is a versioning scheme for using meaningful version numbers to avoid “dependency hell”. Semantic Versioning works by structuring each version identifier into three parts:

  1. MAJOR version when you make incompatible API changes
  2. MINOR version when you add functionality in a backwards compatible manner
  3. PATCH version when you make backwards compatible bug fixes

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. More information about the standard and implementation is on official SemVer.org.

There are a tons of tools implementing SemVer on different platforms and using various programming language. You may even create your own implementation.

Project setup in Azure DevOps

GitVersion is open-source tool which implement semantic versioning approach in variety of platforms like Jenkins, GitHub or Azure DevOps CI/CD:

Continuous IntegrationGitVersion can be used in a Continuous Server pipeline to generate a version number that both labels the build itself and makes the different version variables available to the rest of the build pipeline.
Command LineThe Command Line gives most flexibility by allowing the execution of GitVersion to be customized
MSBuild TaskJust install with NuGet and GitVersion will automatically generate assembly version information that is compiled into the resulting artifact.
LibraryInstall with NuGet and use GitVersion as a software library. Although this is an unsupported option and the API may break even between minor or patch releases, it’s a useful option to some.

Today, I would show you a pretty simple SemVer implementation on Azure DevOps platform using GitVersion tool and yaml pipeline.

If you do not own an account on Azure DevOps, I advise you to do so for free on official page first. The simplest way to start learning is leveraging Azure DevOps Demo Generator and create a dump project choosing from a huge number of solution available:

Here you could find awesome real world Agile/Scrum or Waterfall projects or start your own lab environment playing with Terraform, Docker, Ansible and even ML. This is more that enough to start learning CI/CD.

For purpose of the article, I would create a default project based on Tailwind Traders template. It may take a few minutes to deploy.

Before starting, check out the repo. It contains a lot of interesting tools and scripts. Now, we need only SemVer

Next, go and fork my azure-tools repositorium from here. After it is done, go to project dashboard and open project settings, next ‘Service Connections’ and create new GitHub connection:

Now, we are ready to create a new yaml pipeline. Select GitHub and choose the repository we forked and then ‘Existing Azure Pipelines YAML file’:

GitVersion semantic versioning configuration

To be able to use GitVersion tools, first install extension using Azure DevOps extension tab

Now, lets looks inside the repo. Basically all we need is placed inside SemVer folder:

1. azure-pipelines.yaml – base yaml file we are using to create pipeline. It contains setup parameters and configuration variables.

2. Main template calls calls template.yaml. This is a main logic which install and runs gitversion tool. First use gitversion/setup@0 Azure DevOps task of specific version. Next, gitversion/execute@0 and pass GitVersion.yml configuration file path.

Semantic Versioning

3. GitVersion.yml semver configuration file. What important to know is:

  1. select git flow based on your project flow (ContinuousDeployment, Mainstream and ect)
  2. create separate rules for all of branches on repositorium base on match pattern
  3. exclude specific commits from calculation or all commits (including tags) starting from specific date
  4. increment MAJOR.MINOR.TAGS manually using commit message
  5. and much more

After, a some time GitVersion returns calculated version based on commit in specific moment of time. It is important to note, the version does not change until new commit pushed.

GitVersion is straightforward tool to control versioning base on branch naming policy implemented inside your organization. Here are advantage and some disadvantage of using GitVersion based on my experience. The biggest pros is customization and support for variety of CI/CD tools available on the market. The biggest disadvantage is lack of support of different semantic schemas inside one monorepo project:

ProsCons
Repeatable version control, based on commit historyDOES NOT support separate versioning schema inside monorepo
Clear versioning strategy based on project flowNeeds additional configuration efforts on old control systems
Easy to integrate with external projects, implementing feed strategy
Simple Hotfix and Release flow
Compatible with variety of CI/CD tools, CLI, MSBuild, SDK

Be an ethical, save your privacy!

subscribe to newsletter

and receive weekly update from our blog

By submitting your information, you're giving us permission to email you. You may unsubscribe at any time.

Leave a Comment

Discover more from #cybertechtalk

Subscribe now to keep reading and get access to the full archive.

Continue reading