简体   繁体   English

如何使用 Azure Devops 和 Cake Build 在构建时自动标记和版本化?

[英]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:所以这是我的问题:

  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?如何在 Azure DevOps 构建过程中将版本号添加到我的工件名称?
  4. What do I need to change in my git version code to use the tags?我需要在我的 git 版本代码中更改什么才能使用这些标签?
  5. How do I add suffixes to make versioning and tagging more "git flow" like (such as "pre-release" and so on)?如何添加后缀以使版本控制和标记更像“git 流”(例如“预发布”等)?

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.

相关问题 使用Cake Build创建到远程存储库的标签 - Create Tag to Remote Repository using Cake Build Azure DevOps 在发布/{version} 分支上触发构建 - Azure DevOps Trigger build on release/{version} branch Azure DevOps生成管道无法使用标记和路径筛选器进行生成 - Azure DevOps Build Pipeline cannot build with Tag and Path Filter Azure Devops 服务器:如何设置构建管道以将 git 源作为任务而不是自动获取 - Azure Devops Server: How to setup build pipeline to get git sources as a task instead of geting it automatically 如何使用NAnt与Azure DevOps和Git进行构建? - How to use NAnt to build with Azure DevOps and Git? 如何在Azure DevOps构建期间使用PowerShell脚本将构建工件推送到Git存储库? - How to push build artifacts to Git repository using PowerShell script during Azure DevOps build? 在单独的 Azure DevOps 存储库和构建管道中触发 Package 版本更新 - Triggering A Package Version Update In Separate Azure DevOps Repo and Build Pipeline Azure devops 跳过构建管道 - Azure devops skip build pipline Azure DevOps - 如何使用多个存储库创建构建管道? - Azure DevOps - How do I create a build pipeline using more than one repository? 如何根据提交消息触发 azure devops build pipeline? - How to trigger azure devops build pipeline based on the commit message?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM