【发布时间】:2017-11-02 12:26:14
【问题描述】:
在我们的 BitBucket 中,我们有一些这样的标签:
build-0.0.4.152
0.0.4
build-0.0.3.151
build-0.0.3.150
0.0.3
所有带有前缀“build”的标签都来自中间预发布版本,其中不带前缀的标签是生产中发布的版本。我有一个 gradle 方法可以从 VCS 根目录获取最新的生产标签(所以在这种情况下,我希望得到标签 0.0.4):
def getVersionFromTag() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--abbrev=0', '--match="[!build]*"'
standardOutput = stdout
}
return stdout.toString().trim()
}
在 IntelliJ 本地,构建能够获得正确的标签。但是在 TeamCity 上,它在此处的构建日志中显示错误:
fatal: No names found, cannot describe anything.
如果我从命令行中删除参数'--match="[!build]*"',在上面的方法中,它会工作,但它会得到最新的标签(build-0.0.4.152,但不是我想要的0.0.4)。所以我认为该参数在 TeamCity 的 git 版本中不可用,但在我自己的 git (2.6.3.windows.1) 上可用,是这样吗?
如果我错了,请纠正我,让我知道如何解决这个问题。谢谢
【问题讨论】:
-
--match的模式是一个 glob。git describe --match="[!build]*"表示查找第一个字符不是b、u、i、l或d的最新注释标签。也许你可以使用git describe --abbrev=0 --match="build-*"来获取最新的标签,然后解析它得到0.0.4。
标签: git gradle teamcity git-tag