如何仅为标签运行 TeamCity 构建? [英] How to run a TeamCity build only for tags?

查看:22
本文介绍了如何仅为标签运行 TeamCity 构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个项目可以生成我发布到内部服务器的 NuGet 包.我们正在使用 语义版本控制,并在我们的 Git 存储库中使用标签来控制版本号.

I have several projects that produce NuGet packages that I publish to an internal server. We're using semantic versioning, and using tags in our Git repository to control the version numbers.

我是这样标记的:

git tag -a v1.0.0 -m "tagged"

并且,在 TeamCity 构建期间,我运行 git describe --long,它会产生如下输出:

And, during the TeamCity build, I run git describe --long, which produces an output like this:

v1.0.0-0-ge9c047d

输出中的第四个数字是标记后的提交次数.此处的 0 表示自标记以来未进行任何提交.我使用这前四个数字作为版本号(顺便说一下,整个字符串作为 AssemblyInformationalVersion).

The fourth number in the output is the number of commits after the tag. The 0 here means that no commits have been made since the tag. I use these first four numbers as the version number (and, incidentally, the entire string as the AssemblyInformationalVersion).

我有 TeamCity 包并发布了一个 NuGet 包,但这就是它变得棘手的地方.我只想发布标签,从不在标签之后提交(因为在这种情况下版本号是错误的,可能是非常错误的).

I have TeamCity package and publish a NuGet package, but here's where it gets sticky. I only want to publish tags, never commits after tags (because the version number in that case would be wrong, possibly VERY wrong).

我尝试将 VCS 根目录中的分支规范"设置为+:refs/tags/*",这会导致构建所有标签,但 TeamCity 也坚持构建默认分支".如果我将默认分支"设置为不存在的内容,则会出现错误.

I've tried setting the "branch specification" in the VCS root to "+:refs/tags/*", which causes all the tags to be built, but TeamCity also insists on building the "default branch" as well. If I set the "default branch" to something that doesn't exist, I get an error.

如果特定构建不是标签,我曾考虑过提前结束构建,但如果不使构建失败,我无法弄清楚如何做到这一点,这不是我想要的.

I've thought about ending the build early if a particular build isn't a tag, but I can't figure out how to do that without FAILING the build, which isn't what I want.

如何使一个或多个构建步骤仅针对新标签运行,而不是常规提交?

How do I cause one or more build steps to only run for new tags, and not regular commits?

推荐答案

如果您使用的是 TeamCity 8.x,现在支持 VCS 分支触发器,这将允许您不从默认分支运行构建.

If you are using TeamCity 8.x, there is now support for VCS branch triggers, which would allow you to not run builds from the default branch.

试试这个:

  1. 将 VCS 根目录中的分支规范保留为+:refs/tags/*"
  2. 将 VCS 构建触发规则更改为:

  1. Leave the Branch Specification in the VCS Root as "+:refs/tags/*"
  2. Change the VCS build trigger rules to:

+:*

-:<默认>

-:<default>

这将从触发器中过滤掉默认分支,您无需取消构建.

This will filter out the default branch from the trigger and you won't need to cancel the build.

这篇关于如何仅为标签运行 TeamCity 构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆