如何在 TeamCity 中构建 git 标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20353729/
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-10 17:24:59  来源:igfitidea点击:

How can I build a git tag in TeamCity?

gittagsteamcitygit-checkout

提问by js3dev

I want to provide a git tag to the TeamCity server to build it. I pass the tag (i.e. release_1.1) as a parameter to the job. So inside the job the tag is available as %tag%, but under the Version Control SettingsI don't see any way to use this parameter so the server can checkout this tag. Is there any way this parameter can be used in the settings to checkout the tag?

我想向 TeamCity 服务器提供一个 git 标签来构建它。我将标签(即release_1.1)作为参数传递给作业。因此,在作业内部,该标签可用作%tag%,但在 下Version Control Settings我看不到任何使用此参数的方法,因此服务器可以检出此标签。有什么办法可以在设置中使用此参数来检查标签吗?

回答by Michel Samia

  1. Go to Edit Configuration Settings -> Version Control Settings
  2. For all your VCS roots for this build configuration click Edit and then:

    1. put '+:refs/tags/*' into Branch specification textbox
    2. check Use tags as branches
  1. 转到编辑配置设置 -> 版本控制设置
  2. 对于此构建配置的所有 VCS 根,单击编辑,然后:

    1. 将 '+:refs/tags/*' 放入分支规范文本框
    2. 检查使用标签作为分支

Then you'll be able to choose a tag when you press the '...' button beside run.

然后,当您按下 run 旁边的“...”按钮时,您将能够选择一个标签。

回答by Zhaph - Ben Duguid

I've managed to get the following working:

我设法使以下工作:

In the Build Configuration, under "Build Parameters":

在构建配置中,在“构建参数”下:

Define a Configuration Parameter:

定义配置参数

  • Name: TagToBuild
  • Kind: Configuration parameter
  • Value:
  • Spec:
    • Label: Tag to build
    • Description: This should be the full path to the tag, i.e. refs/tags/0.5.5
    • Display: Prompt
    • Type: Text
  • 姓名: TagToBuild
  • 种类: Configuration parameter
  • 价值:
  • 规格:
    • 标签: Tag to build
    • 描述: This should be the full path to the tag, i.e. refs/tags/0.5.5
    • 展示: Prompt
    • 类型: Text

Note that the "value" field was intentionally left blank.

请注意,“值”字段有意留空。

Then, in the VCS Root:

然后,在 VCS 根中:

  • Branch Name: %TagToBuild%
  • 分店名称: %TagToBuild%

When I run the build, I'm then prompted to supply a branch/tag name: Configuration Parameters

当我运行构建时,系统会提示我提供一个分支/标签名称: 配置参数

Entering a value such as refs/tags/0.5.0results in a nice build, with the branch name listed in the results: Successful builds

输入一个值,例如refs/tags/0.5.0结果在一个不错的构建中,结果中列出了分支名称: 成功构建

If you try to help the user in any waybeyond the description, this seems to fail. So you can't do any of the following:

如果您试图以超出描述的任何方式帮助用户,这似乎失败了。因此,您不能执行以下任何操作:

  1. In the Configuration Parameter set the "Value" to refs/tags/and have the user add the tag name.
  2. In the VCS Root set the "Branch Name" to refs/tags/%TagToBuild%.
  1. 在配置参数中将“值”设置为refs/tags/并让用户添加标签名称。
  2. 在 VCS Root 中,将“分支名称”设置为refs/tags/%TagToBuild%.

In both cases on our slightly old (7.1) instance of Team City I got the error:

在我们稍微旧的 (7.1) Team City 实例的两种情况下,我都收到了错误:

Failed to collect changes, error: Argument 2 for @NotNull parameter of jetbrains/buildServer/buildTriggers/vcs/VcsRootChangesLoader.loadChanges must not be null

无法收集更改,错误:jetbrains/buildServer/buildTriggers/vcs/VcsRootChangesLoader.loadChanges 的 @NotNull 参数的参数 2 不能为空

回答by robrich

I've not done this with tags, but I've done this with branches. I tell TeamCity to build all branches by specifying it should build +:refs/heads/*. Now whenever I push any branch, TeamCity builds it. Then within the build I then use git branchand look for the line that starts with a *. I embed that branch name in a convenient spot (AssemblyInfo.cs for .NET, package.json for node.) see http://confluence.jetbrains.com/display/TCD8/Working+with+Feature+Branches

我没有用标签做过这个,但我用分支做过这个。我告诉 TeamCity 通过指定它应该构建来构建所有分支+:refs/heads/*。现在,每当我推送任何分支时,TeamCity 都会构建它。然后在构建中我使用git branch并查找以*. 我将该分支名称嵌入到一个方便的位置(用于 .NET 的 AssemblyInfo.cs,用于节点的 package.json。)参见http://confluence.jetbrains.com/display/TCD8/Working+with+Feature+Branches

回答by Welsh

You need to specify the tag format in refs/tags/${tagName}.

您需要在refs/tags/${tagName}.

So yours would be refs/tags/release_1.1.

所以你的将是refs/tags/release_1.1