Include git branch name and latest commit SHA in TeamCity successfull email template

4.3k views Asked by At

I have to include branch name and latest git commit SHA in TeamCity successful email template.

I've added these lines to the standard build_successful.ftl email template file:

<#global body>
...

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

...
</#global>

but got this email:

Commit: 77
Branch: [TEAMCITY TEMPLATE ERROR]

I've found that TC server side API model exposes these methods: 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()

I can't figure out how to obtain required info.

We are using:

  • TeamCity 8
  • git provider by JetBrains
  • windows host
2

There are 2 answers

0
pocheptsov On BEST ANSWER

I've got a correct answer from official JetBrains support forum:

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

1
John Hoerr On

You might try

Branch: ${build.vcs.number}

This gives you the "VCS revision number of the first VCS root attached to the configuration." If your git source is not the first attached root, you can append an index to select it:

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