[英]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.我正在使用 Cake 脚本通过持续集成在 Azure DevOps 中构建我的软件。 The requirement is that when we commit/merge into to the dev or master branch, the appropriate build pipeline(s) are kicked off.要求是当我们提交/合并到 dev 或 master 分支时,启动适当的构建管道。 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:我的 cake 脚本中有以下代码已经使用 GitVersion 将语义版本控制添加到我的构建中:
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.或者我希望管道自动对软件和我们在构建管道末尾创建的最终 zip 工件进行版本控制。
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.我这有点宽泛,但我正在努力寻找在 Cake Build 中使用 git 版本控制和 git 标记并将其以有意义的方式连接到 Azure DevOps 的任何示例。 Thanks in advance.提前致谢。
GitVersion has a default global configuration which is used to automatically calculate a Semantic Version of your code. GitVersion 有一个默认的全局配置,用于自动计算代码的语义版本。 By default, GitVersion is heavily influenced by the GitFlow model of branching.默认情况下,GitVersion 深受 GitFlow 分支模型的影响。 It also supports GitHubFlow with minimal changes to its configuration.它还支持 GitHubFlow,只需对其配置进行最少的更改。
GitVersion has some documentation here . GitVersion在这里有一些文档。
For anything that's well off the beaten path of GitFlow or GitHubFlow, you can provide your own configuration.对于任何与 GitFlow 或 GitHubFlow 不同的地方,您都可以提供自己的配置。 You can also create custom branch configurations (ie for branches that are not used in either GitFlow or GitHubFlow).您还可以创建自定义分支配置(即,用于 GitFlow 或 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.但是 GitVersion 相当灵活。
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.我在 15 分钟内为我设置了一些简单的东西,这足以作为一个最小可行的概念。 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.至于标记,一旦您在 Cake 脚本中使用 GitVersion 来计算版本,您可以从 Cake 脚本中发出命令以生成 Git 标记,可能来自MajorMinorPatch
属性,该属性在针对您的代码库运行GitVersion
时获取输出,并从同一个 Cake 脚本中发出git tag
命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.