Versioning your ARM templates within a VSTS CI/CD pipeline with Semantic Versioning

I wrote a post recently Versioning your ARM templates within a VSTS CI/CD pipeline. I realised since writing it that it does not address the issue of if you wish to version your ARM Templates using Semantic Versioning. My JSON versioning task I used did not support the option of not extracting a numeric version number e.g. 1.2.3.4 from a VSTS build number. To address this limitation I have modified my Version JSON file task to address. This change to my task allows it to be used with the GitVersion VSTS task to manage the semantic versioning. For more details on GitVersion see the project documentation. Hence, I my now able to generate a version number using GitVersion and pass this in to the versioning task directly using a build variable.

  • Add the GitVersion task at the start of the build, with its default parameters
  • Add my JSON versioning task with default parameters apart from
    • Version Number set to $(GitVersion.SemVer)
    • Use Version Number without Processing (Advanced) checked
    • Filename Pattern (Advanced) set to azuredeploy.json
    • Field to update (Advanced) set to contentVersion

image In the logs you see output similar to the following``` Source Directory: E:Build2_work361s Filename Pattern: azuredeploy.json Version Number/Build Number: 0.1.0-unstable.843 Use Build Number Directly: true Version Filter to extract build number: d+.d+.d+.d+ Version Format for JSON File: {1}.{2}.{3} Field to update (all if empty): contentVersion Output: Version Number Parameter Name: OutputedVersion Using the provided build number without any further processing JSON Version Name will be: 0.1.0-unstable.843 Will apply 0.1.0-unstable.843 to 12 files. Updating the field 'contentVersion' version Existing Tag: contentVersion": "1.0.0.0" Replacement Tag: contentVersion": "0.1.0-unstable.843" …