在TeamCity成功的电子邮件模板中包含git分支名称和最新提交SHA

3

我需要在TeamCity的成功邮件模板中包含分支名称和最新的Git提交SHA。

我已经在标准的build_successful.ftl邮件模板文件中添加了以下内容:

<#global body>
...

Commit: ${build.buildNumber}
Branch: ${build.branch.displayName}

...
</#global>

但我收到了这封邮件:

Commit: 77
Branch: [TEAMCITY TEMPLATE ERROR]

我发现TC服务器端API模型提供了以下方法: http://javadoc.jetbrains.net/teamcity/openapi/8.0/jetbrains/buildServer/Build.html#getBuildNumber() http://javadoc.jetbrains.net/teamcity/openapi/8.0/jetbrains/buildServer/serverSide/Branch.html#getDisplayName() 我无法弄清如何获取所需信息。
我们使用的是:
- TeamCity 8 - JetBrains提供的git版本控制 - Windows主机
2个回答

2

我从官方JetBrains支持论坛得到了正确的答案:

If you want to include information about build revisions in your notification you can try using something like this (see also SBuild.getRevisions method):

  <#list build.revisions as revision>
    Revision: ${revision.repositoryVersion.displayVersion}
    VCS branch:  ${revision.repositoryVersion.vcsBranch}
  </#list>   

A couple of notes:

  • there can be more than one VCS root in build, so number of revisions corresponds to number of VCS roots
  • if changes are not yet collected for the build, or some error occurred while changes collecting, collection of revisions will be empty.

Pavel Sher


2
你可以尝试一下:
Branch: ${build.vcs.number}

这将给出“配置所附加的第一个版本控制系统根目录的VCS修订号。” 如果您的git源不是第一个附加的根目录,您可以附加一个索引来选择它:

Branch: ${build.vcs.number.1}

${build.vcs.number} 给出相同的错误 - [TEAMCITY TEMPLATE ERROR] - pocheptsov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接