Teamcity 9:如何将 git short hash 添加到程序集信息修补程序中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30416789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:02:39  来源:igfitidea点击:

Teamcity 9: How to add git short hash into assembly info patcher

gitteamcityteamcity-9.0

提问by Neil P

I'm trying to use assembly info patcher to create a version number something like:

我正在尝试使用程序集信息修补程序来创建类似以下内容的版本号:

1.2.3.1a3c19e

1.2.3.1a3c19e

where the last bit is the git short hash.

其中最后一位是 git 短哈希。

I've tried using a powershell script build step to create the short hash (as I cant find a variable that has it) and adding this to a system variable but this build step appears to run after assembly info patcher, so isn't much use.

我已经尝试使用 powershell 脚本构建步骤来创建短哈希(因为我找不到包含它的变量)并将其添加到系统变量中,但是这个构建步骤似乎是在程序集信息修补程序之后运行的,所以不是很多用。

回答by Evolve Software Ltd

If you want to write this to the Assembly Info field it can be done, but it requires a separate build configuration to generate the build number. The sole purpose of this step is to create the build number that has the hash appended to it.

如果您想将其写入 Assembly Info 字段,则可以完成,但需要单独的构建配置来生成构建编号。此步骤的唯一目的是创建附加了哈希的内部版本号。

1. Create a build configuration to generate the short hash

1. 创建构建配置以生成短哈希

Build Config

构建配置

2. Add a step to generate the hash

2. 添加生成hash的步骤

Build Config

构建配置

3. Add a parameter to store the hash

3.添加一个参数来存储hash

Param

参数

4. Add a second build configuration and add a dependency to the first one

4.添加第二个构建配置并为第一个添加依赖项

Dependency

依赖

5. You can now consume the parameter in the dependent step

5.您现在可以在依赖步骤中使用参数

Consume

消耗

6. At this point you can use it in the assembly info patcher

6.此时就可以在程序集信息补丁中使用了

Patcher

修补程序

The alternative to this is to write your build number back to Git using the VCS labeling build feature.

另一种方法是使用 VCS 标签构建功能将您的构建号写回 Git。

Labeling

标签

Hope this helps.

希望这可以帮助。

回答by Alexey Andrushkevich

If you mean .NET assembly you will not be able to use git's short hash as the revision number just because it accepts numbers only. You can check it yourself and put the version above to AssemblyVersion. I bet your app will not be compiled. Instead you can use %build.counter% variable from teamcity as the revision number.

如果您的意思是 .NET 程序集,您将无法使用 git 的短哈希作为修订号,因为它只接受数字。你可以自己查一下,把上面的版本放到AssemblyVersion。我打赌你的应用程序不会被编译。相反,您可以使用 teamcity 中的 %build.counter% 变量作为修订号。