如何使用修订号而不是 GUID(在 TeamCity 中)标记我的构建?

发布于 2024-10-05 20:39:16 字数 347 浏览 1 评论 0原文

我正在尝试与 TeamCity 进行“持续集成”。我想以增量方式标记我的构建,而 VCS 提供的 GUID 不如简单递增的数字那么有用。我希望该数字与 Mercurial 中的修订版数字实际匹配。

我的状况:

alt text

Mercurial 信息:

alt text

我希望将构建标记为 0.0.12 而不是 GUID。

有人会如此友善并节省我尝试解决这个问题的时间吗?

I am trying to do "continuous integration" with TeamCity. I would like to label my builds in a incremental way and the GUID provided by the VCS is not as usefull as a simple increasing number. I would like the number to actually match the revision in number in Mercurial.

My state of affairs:

alt text

Mercurial info:

alt text

I would like the build to be labeled 0.0.12 rather than the GUID.

Would someone be so kind and save me hours of trying to figure this out ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

多情癖 2024-10-12 20:39:16

正如 Lasse V. Karlsen 提到的,这些数字修订号是本地克隆特定的,并且对于每个克隆来说可能不同。它们确实不适合版本控制——您可以重新克隆相同的存储库并获得不同的修订号。

至少包含节点 ID 来创建类似于 0.0.12-6ec760554f2b 的内容,那么您仍然可以获得可排序的版本工件,但仍然可以牢固地识别您的版本。

如果您使用数字标签来标记版本,那么有一个特别好的选项:

% hg log -r tip --template '{latesttag}.{latesttagdistance}'

如果该克隆上的最新标签名为 1.0.1 并且是在 84 之前提交的给出如下值:

1.0.1.84

由于您可以在不同存储库中拥有距离标记 84 次提交的不同头,因此您仍然应该包含节点 ID,如:

% hg log -r tip --template '{latesttag}.{latesttagdistance}-{node|short}'

Give:

1.0.1.84-ec760554f2b

这会生成一个 great 版本字符串。

As Lasse V. Karlsen mentioned those numerical revision numbers are local-clone specific and can be different for each clone. They're really not suitable for versioning -- you could reclone the same repo and get different revision numbers.

At the very least include the node id also creating something like 0.0.12-6ec760554f2b then you still get sortable release artifacts but are still firmly identifying your release.

If you're using numeric tags to tag releases there's a particularly nice option:

% hg log -r tip --template '{latesttag}.{latesttagdistance}'

which, if the most recent tag on that clone was called 1.0.1 and was 84 commits ago gives a value like:

1.0.1.84

Since you can have different heads that are 84 commits away from a tag in different repos you should still probably include the node id like:

% hg log -r tip --template '{latesttag}.{latesttagdistance}-{node|short}'

giving:

1.0.1.84-ec760554f2b

which makes a great version string.

寄离 2024-10-12 20:39:16

查看转速的最佳和最简单的方法。 TeamCity 内部版本号中的数字是使用构建与 TeamCity 的脚本交互。也就是说,它可以设置内部版本号< /a>.

因此,向您的项目添加一个新的第一个构建步骤命令行,其中包含以下命令可执行文件

for /f %%i in ('c:\tortoisehg\hg id -n') do echo ##teamcity[buildNumber '%%i']

,您将获得 Mercurial 修订号作为每个构建的标签。

当然,您可以将引号中的命令更改为您想要的任何内容。

我相信我的答案比接受的答案更正确。

编辑:

您也可以通过 MSBuild 任务而不是命令可执行文件执行相同的操作。拥有一个包含以下代码的 MSBuild 项目文件,第一步设置 TeamCity 来运行它,它将更改其全局变量 buildNumber

<Message Text="##teamcity[buildNumber '$(CurrentVersion)']" Importance="High" />

其中 CurrentVersion 是包含完整版本的字符串 (例如“1.0.56.20931”)。

The best and easiest way to see rev. number in TeamCity build number is to use Build Script Interaction with TeamCity. Namely, it has a possibility to set Build Number.

So, add to your project a new very first build step Command Line with following Command Executable

for /f %%i in ('c:\tortoisehg\hg id -n') do echo ##teamcity[buildNumber '%%i']

And you will get the Mercurial revision number as a label for your every build.

Of course you can change the command in quotes to anything you wish.

I believe my answer is way more correct than the accepted one.

EDIT:

Also you can do the same via MSBuild task rather than Command Executable. Have a MSBuild project file with following code, setup TeamCity to run it as first step, and it will alter its global variable buildNumber:

<Message Text="##teamcity[buildNumber '$(CurrentVersion)']" Importance="High" />

Where CurrentVersion is a string containing full version (for example "1.0.56.20931").

浅紫色的梦幻 2024-10-12 20:39:16

hg id 生成哈希值 (6ec760554f2b),hg id -n 生成本地修订号 (12)。

(请注意,这纯粹是来自 hg 方面的答案,我不知道如何将其放入 TeamCity,因为我从未使用过它。)

hg id produces the hash (6ec760554f2b), hg id -n produces the local revision number (12).

(Note this is an answer purely from the hg side, how you then get that into TeamCity, I don't know, as I've never used it.)

幽梦紫曦~ 2024-10-12 20:39:16

我设法通过解决方法在 Teamcity 中使用它:

    <Exec Command="hg log -r tip --template {latesttag}.{latesttagdistance} > $(BuildAgentTempDir)\version.txt"/>
    <ReadLinesFromFile File="$(BuildAgentTempDir)\version.txt">
        <Output TaskParameter="Lines" ItemName="versionInfo"/>
    </ReadLinesFromFile>
    <TeamCitySetBuildNumber BuildNumber="@(versionInfo)-{build.number}" />

如果您看到 MSBuild 任务“TeamCitySetBuildNumber”,我正在使用“{build.number}”变量,因为它会将其替换为您最初在内部版本号中设置的内容。我在原始设置(在 Web UI 中)中使用了 %build.vcs.number%,结果正是 Ry4an 上面写的!

希望它对你有用!

I managed to use it in Teamcity using a workaround:

    <Exec Command="hg log -r tip --template {latesttag}.{latesttagdistance} > $(BuildAgentTempDir)\version.txt"/>
    <ReadLinesFromFile File="$(BuildAgentTempDir)\version.txt">
        <Output TaskParameter="Lines" ItemName="versionInfo"/>
    </ReadLinesFromFile>
    <TeamCitySetBuildNumber BuildNumber="@(versionInfo)-{build.number}" />

If you see the MSBuild task "TeamCitySetBuildNumber" I'm using the "{build.number}" variable because it substitutes this with what you set in the build number originally. I used %build.vcs.number% in my original settings (in the Web UI) and the result is just what Ry4an wrote above!

Hope it works for you!

日裸衫吸 2024-10-12 20:39:16

当我使用 Subversion 时,我曾经在 TeamCity 中做过类似的事情。格式是:

{Major}.{Minor}.{TeamCity Build No.}.{Subversion Revision No.}

这使我能够查看程序集并查看它来自 TeamCity 上的哪个版本以及来自 subversion 的修订号。

我现在已经转向 Git,这让我遇到了和你一样的情况。在考虑了各种想法之后,我得出的结论是我实际上不需要修改,构建已经足够好了。由于 TeamCity 是一个非常强大的工具,您所需要的只是内部版本号,有了内部版本号,您就可以查看内部版本历史记录并从中确定修订版本。

{Major}.{Minor}.{Macro}.{TeamCity Build No.}

此外,您还可以让 TeamCity 使用内部版本号来标记您的存储库,从而允许您在源代码管理中查找给定的内部版本。

When I used to use Subversion I used to do something similar in TeamCity. The format was:

{Major}.{Minor}.{TeamCity Build No.}.{Subversion Revision No.}

This allowed me to look at an assembly and see which build it came from on TeamCity and the revision number from subversion.

I have now moved to Git which has put me in the same situation as you. After playing with various ideas I have come to the conclusion that I don't actually need the revision, the build is good enough. Because TeamCity is such a powerful tool, all you need is the build number, given the build number you can look at the build history and determine the revision from that.

{Major}.{Minor}.{Macro}.{TeamCity Build No.}

Additionally you can get TeamCity to label your repository with the build number allowing you to look up a given build in your source control.

橪书 2024-10-12 20:39:16

在为您的版本号提供数字 Mercurial 修订版时,您必须注意,这些数字是特定于克隆的,并且可能因克隆而异。

在我们的项目中,我们遇到了同样的问题。我们使用的是 TeamCity 7.1.1。我们通过以下方式解决了这个问题:

  1. 将命令行构建步骤添加到您的配置中。
  2. 首先运行此构建步骤。
  3. 在构建步骤属性中,选择“运行:‘带有参数的可执行文件’”,
  4. 将以下文本添加到命令可执行文件中:

for /f %%i in ('hg id -n') do echo ##teamcity[buildNumber '% %i']

 Save changes.

执行步骤 3 时,您还可以使用之前生成的内部版本号。

示例:

for /f %%i in ('hg id -n') do echo ##teamcity[buildNumber '%system.build.number%.%%i']

您可以使用它使内部版本号中出现内部版本号。 >

阅读以获取更多信息!

请记住,teamcity 在构建开始之前编译配置构建号只有在构建步骤完成其工作后才会出现正确的构建号。这就是为什么在某些情况下(例如插入您的 Mercurial 修订版为工件的名称)您应该在前面的配置中定义内部版本号的值并引用它。

示例:

%dep.bt82.build.number%

阅读此内容 获取更多信息!

When providing your build number with numeral mercurial revision, you must be aware, that those numbers are clone-specific and can differ from clone to clone.

In our project we had the same issue. We're using TeamCity 7.1.1. We solved it in the following way:

  1. Add Command line build step to your configuration.
  2. Make this build step run first.
  3. In the build step properties select "Run: 'Executable with parameters'"
  4. Add the following text to Command Executable:

for /f %%i in ('hg id -n') do echo ##teamcity[buildNumber '%%i']

 Save changes.

You can also use previously generated build number when performing step 3.

Example:

for /f %%i in ('hg id -n') do echo ##teamcity[buildNumber '%system.build.number%.%%i']

You can use this to make build counter present in your build number.

Read this to get more information!

Remember that teamcity compiles configurations build number before build starts and the correct build number will appear only after your build step will finish its job. That's why, in some cases (f.e. inserting your mercurial revision into artifact's name) you should define build number's value in preceding configuration and refer to it.

Example:

%dep.bt82.build.number%

Read this to get more information!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文