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:
Task("Version")
.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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With