Custom text in email notifications

Hi,

I'm using TeamCity 6.0.1, and want to include custom text into an email. More specifically, one of our agents is restoring a database backup, and I want to specify backup name in the email. I noticed, that if my build log reports an error by writing ##teamcity[buildStatus status='FAILURE' text='XxxMessage.'] then XxxMessage is included in the email, and I'm assuming this text is bound to ${var.buildShortStatusDescription} variable of build_failed.ftl template.

So, two questions now:

  1. Is there a similar (easy) way to pass over my backup file name to the email?
  2. Is it possible to customize emails for one build agent only? (In my case, only one build agent restores the backup, so only its notification should contain file name)



Thanks,
Andrew

4 comments
Comment actions Permalink

Hi Andrew,

You're right, the service message ##teamcity[buildStatus ...] is used to update the status of the build, and then it can be accessed via ${var.buildShortStatusDescription} in notification template.

| Is there a similar (easy) way to pass over my backup file name to the email?
In order to have this information in the email template, you need to associate the backup file name with the build, i.e. include this name into the status, or print it to stdout and have it in the build log, etc.
After this the file name should be extracted: from the string if you use the build status, or from the build log messages.
All of these methods work, but I wouldn't say it is so easy.

| Is it possible to customize emails for one build agent only? (In my case, only one build agent restores the backup, so only its notification should contain file name)
Yes, the agent name is accessible in the template (see "build_agent" macro in common.ftl), so you can have a conditional statement that forms a special email for a certain agent.


Hope this helps.


--
Maxim

0
Comment actions Permalink

Hi Maxim, thanks for the reply.

"..After this the file name should be extracted: from the string if you use the build status, or from the build log messages..." - that's the most interesting part :) Can you be more explicit here? How can I define "var.BackupName" and read/write text there?

I'm using powershell script at the lower level but I'm ok using normal .bat if needed

Thanks,
Andrew

0
Comment actions Permalink

Hi Andrew,

That depends on how you want to pass the data to the build. The best way is to write the plugin to TeamCity that will do all the work (without hacks) and will pass additional data to the template.
If you don't choose this way, you can only use the standard variables in the template, ${build}, ${project}, ... From the ${build} you can get the status and build log, and FreeMarker allows to extract a substring and iterate over the list of log messages.



The final decision greately depends on how fast you want to achieve the goal, the desired code quality, etc. So far I don't see an ideal solution.


---
Maxim
0
Comment actions Permalink

Fair enough, thanks! Looks like my idea will probably have to wait, for now..

0

Please sign in to leave a comment.