Add git tags and versioning to mark Deployments in Azure DevOps Pipelines

This post shows how to tag to a git repository after a successful deployment or release. The tag is created using the version number of the build. The version number can be changed or set using Nerdbank.GitVersioning. The DevOps extension Tag\Branch Git on Release by Michael Barry was used to implement the tagging. This extension needs to be installed to your Azure DevOps. Instructions how to install DevOps extensions can be viewed here. This can be tricky if you have multiple accounts.

To add a git tag to the test or production releases, the following yaml code can be added to the Azure DevOps pipeline. I usually use a prefix to mark the target deployment, so the latest release for each deployment can be found quicker in the git repository. For example, if I have four deployments for a software system, dev, test, prod and securityaudit, I would add the prefix for each deployment, and this followed by the actual software version. I would add no tag to the dev deployment. Here is a simple example of a git tag created for the test deployment.

- stage: tag
  displayName: "Create git Tag"
  jobs:
  - job: tag
    steps:
    - task: git-tag-on-release-task@9
      displayName: "Add Tag to git"
      inputs:
        staticTagName: "TEST-$(Build.BuildNumber)"

Versioning

I like to version the assemblies, Nuget packages for each deployment. Nerdbank.GitVersioning is a good dotnet cli tool for doing this, but not the only way of creating versioning. Nerdbank.GitVersioning versioning can be added to the Azure DevOps build as follows:

- task: DotNetCoreCLI@2  
  displayName: Install NBGV tool
  inputs:
	command: custom
	custom: tool
	arguments: install --tool-path . nbgv

- script: nbgv cloud
  displayName: Set Version

See this blog for details on Nerdbank.GitVersioning:

https://ml-software.ch/posts/versioning-made-easier-with-nerdbank-gitversioning

This can be viewed in git extensions.

Adding a version to Nuget packages

The version can also be added to Nuget packages created in your pipeline. By using the versioningScheme set to byBuildNumber, the Build.BuildNumber is used to create the Nuget package.

- task: DotNetCoreCLI@2
  displayName: "Pack"
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    versioningScheme: 'byBuildNumber'

Links tagging

https://marketplace.visualstudio.com/items?itemName=jabbera.git-tag-on-release-task

https://docs.microsoft.com/en-us/azure/devops/marketplace/install-extension

https://marketplace.visualstudio.com/azuredevops

Links versioning

https://github.com/dotnet/Nerdbank.GitVersioning/blob/master/doc/nbgv-cli.md

https://ml-software.ch/posts/versioning-made-easier-with-nerdbank-gitversioning

https://github.com/adamralph/minver

2 comments

  1. […] Add git tags and versioning to mark Deployments in Azure DevOps Pipelines (Damien Bowden) […]

  2. […] Add git tags and versioning to mark Deployments in Azure DevOps Pipelines – Damien Bowden […]

Leave a reply to The Morning Brew - Chris Alcock » The Morning Brew – #2977 Cancel reply

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