Logo Questions Linux Laravel Mysql Ubuntu Git Menu

How to tag and version automatically on build using Azure Devops and Cake Build?

I am using Cake scripts to build out my software in Azure DevOps through continuous integration. The requirement is that when we commit/merge into to the dev or master branch, the appropriate build pipeline(s) are kicked off. As part of this build we need to tag and version our software automatically. I have the following code in my cake script already to use GitVersion to add the semantic versioning to my build:

    .Does(() => 
        Information("Versioning software for configuration {0} of {1}...", configuration, solution);
        GitVersion(new GitVersionSettings {
            UpdateAssemblyInfo = true,
            OutputType = GitVersionOutput.BuildServer,
            WorkingDirectory = toolsDirectory
        GitVersion versionInfo = GitVersion(new GitVersionSettings{ OutputType = GitVersionOutput.Json });

        Information("Semantic Version: " + versionInfo.AssemblySemVer);
        Information("Full Semantic Version: " + versionInfo.AssemblySemFileVer);
        Information("Informational Version: " + versionInfo.InformationalVersion);

I want the team lead or someone in authority to increment the major and minor build versions before this code is merged in with the branch. Or I want the pipeline to auto version the software and the eventual zip artifact we create at the end of the build pipeline.

So here are my questions:

  1. How do I automatically increment my version numbers and tags?
  2. Should I avoid auto incrementing?
  3. How do I add the version number to my artifact name in the Azure DevOps build process?
  4. What do I need to change in my git version code to use the tags?
  5. How do I add suffixes to make versioning and tagging more "git flow" like (such as "pre-release" and so on)?

I this is a bit broad, but I am struggling to find any examples of using git versioning and git tagging within Cake Build and connecting that to Azure DevOps in a meaningful way. Thanks in advance.

like image 640
Ross Gustafson Avatar asked Nov 06 '22 18:11

Ross Gustafson

1 Answers

GitVersion has a default global configuration which is used to automatically calculate a Semantic Version of your code. By default, GitVersion is heavily influenced by the GitFlow model of branching. It also supports GitHubFlow with minimal changes to its configuration.

GitVersion has some documentation here.

For anything that's well off the beaten path of GitFlow or GitHubFlow, you can provide your own configuration. You can also create custom branch configurations (i.e. for branches that are not used in either GitFlow or GitHubFlow).

Their documentation is not great. It's not well organized. I find I just have to play with things to truly understand how it works. But GitVersion is fairly flexible.

I would encourage you to read the documentation and play around with it. It should be possible for you to automatically version your code based on your commits to various branches, at build time, without requiring human intervention (apart from perhaps a commit here and there to force the version number to bump in some part). I got something simple set up for me in under 15 minutes that's good enough as a Minimally Viable Concept. And with a bit more tweaking, I'm confident I'd be able to start using this as part of my normal build process in no time.

As for tagging, once you've used GitVersion in a Cake script to calculate the version, you could issue a command from within your Cake script to generate a Git tag, perhaps from the MajorMinorPatch property that gets output when running GitVersion against your codebase, and issue the git tag command from within that same Cake script.

like image 187
fourpastmidnight Avatar answered Nov 15 '22 04:11