Adding error information to TeamCity email notifications

JetBrain’s TeamCity is a pretty decent Continuous Integration Server. It’s my go-to CI Server of choice. I’ve set it up in a number of workplaces and convinced a few companies to buy Enterprise licences for it.

Unfortunately there are times when building solutions in TeamCity fails, and the Build Failure notifications TeamCity sends do not always have useful failure information in. I’m currently working on a C# project and the failure notices generated by TeamCity don’t contain anything other than the Visual Studio Online changeset details. I’ve got developers on my team who are stubborn and refuse to act on failure notices because TeamCity isn’t telling them what’s wrong with the build (we’ll ignore the fact I think it should be a disciplinary offence to ignore build failure notices)…

So – you’re a CI developer. Your TeamCity instance isn’t sending useful error information. What can you do? Well, you can add the following to your build_failed.ftl template:

<#list build.buildLog.messages[0..] as message>
<#if message.text?contains(“errorreport”)>
<#elseif message.text?contains(“error”)>
${message.text}
</#if>
</#list>

The above code when added to the email notification template will loop through the Build Log messages from your failed build, and include any lines containing the word “error” in the body of the email. Take special note that I have an if condition for “errorreport” also – in my build configuration there are instances of system commands with an /errorreport switch being sent to a program. I don’t want those lines included in the email otherwise it would confuse my already stubborn developers.

You can check your build logs for the best words to match an error line on and adapt the code chunk above to meet your needs.

The Email Notification templates for TeamCity are located in your TeamCity’s data folder. This is usually C:\ProgramData\JetBrains\TeamCity\config\_notifications\email on Windows. For all Operating Systems, using the latest builds of TeamCity (at least 2016 or newer), you should be able to see the data path from the Administration > Server Administration > Global Settings page for all environments.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.