Email template addition

Hi,

I did the following:

Added this code to common.ftl:
<#macro triggered_by build>
  <#-- @ftlvariable name="build" type="jetbrains.buildServer.serverSide.SBuild" -->
  <div>Triggered by: ${build.triggeredBy.user.descriptiveName}</div>
</#macro>




Added this to build_successful.ftl:
  <@common.triggered_by build/>


The result in email is this:

Triggered by: [TEAMCITY TEMPLATE ERROR]

I think I have the triggered by value set incorrectly. I haven't been able to find where it is defined.

What should the value be?

Thanks,

-Dave

0
12 comments
Avatar
Permanently deleted user

Hi Dave,

I don't see any obvious errors in your code. You can find the details in your teamcity-notifications.log file (try to enable DEBUG if you there is no one).
Is it possible that that particular build wasn't triggered by anyone?
Thanks.

---
Maxim

0
Avatar
Permanently deleted user

Shouldn't the triggeredBy user either be "teamcity" or, if launched manually, then be the particular user?

This is what is in the log:
[2010-11-18 20:24:16,989]   WARN - .notification.FreeMarkerHelper - Expression build.triggeredBy.user is undefined on line 9, column 17 in email/build_successful.ftl.
[2010-11-18 20:30:26,674]   WARN - .notification.FreeMarkerHelper - Expression build.triggeredBy.user is undefined on line 9, column 17 in email/build_successful.ftl.
[2010-11-18 23:16:30,858]   WARN - .notification.FreeMarkerHelper - Expression build.triggeredBy.user is undefined on line 9, column 17 in email/build_successful.ftl.

0
Avatar
Permanently deleted user

Hi Dave,

That's right, but you're asking for a particular user, which is nullable.
You can try calling TriggeredBy.isTriggeredByUser() or simply TriggeredBy.getRawTriggeredBy().


---
Maxim

0
Avatar
Permanently deleted user

maxim.podkolzine wrote:

Hi Dave,

That's right, but you're asking for a particular user, which is nullable.
You can try calling TriggeredBy.isTriggeredByUser() or simply TriggeredBy.getRawTriggeredBy().


---
Maxim


Neither of the suggested values work. The way I had as above worked  if a user manually launched a build. So, I set a conditional statement  similar to the way comments work:
<#macro triggered_by build>
   <#-- @ftlvariable name="build" type="jetbrains.buildServer.serverSide.SBuild" -->
   <#if build.triggeredBy??>
     <div>Triggered by: ${build.triggeredBy.user.descriptiveName}</div>
   </#if>
</#macro>

But, it seems as if there must be a way to always display who triggered a build.

-Dave

0
Avatar
Permanently deleted user

Hi Dave,

Thanks for the report. It seems SBuild.getTriggeredBy() can be null, though I can't figure out how this is possible...
Can I ask you to reproduce the situation when it is null:
<#if build.triggeredBy??>
  <div>Triggered by: ${build.triggeredBy.user.descriptiveName}</div>
<#else>
  <div>${build.buildId}</div>
</#if>

I'll try to investigate the issue.


---
Maxim

0
Avatar
Permanently deleted user

maxim.podkolzine wrote:

Hi Dave,

Thanks for the report. It seems SBuild.getTriggeredBy() can be null, though I can't figure out how this is possible...
Can I ask you to reproduce the situation when it is null:
<#if build.triggeredBy??>
  <div>Triggered by: ${build.triggeredBy.user.descriptiveName}</div>
<#else>
  <div>${build.buildId}</div>
</#if>

I'll try to investigate the issue.


---
Maxim


As it turns out, the original conditional statement I mention above (without the else clause) did nothing. When a user starts a build, the "Triggered by" message in email was okay:
Triggered by: Dave Leskovac
when Teamcity starts a build the msg in email is:
Triggered by: [TEAMCITY TEMPLATE ERROR]

When the email error occurs, this gets logged in teamcity-notifications.log:
[2010-11-23 14:17:22,789]   WARN - .notification.FreeMarkerHelper - Expression build.triggeredBy.user is undefined on line 9, column 17 in email/build_successful.ftl.
[2010-11-23 14:17:22,791]   WARN - .notification.FreeMarkerHelper - Expression build.triggeredBy.user is undefined on line 15, column 26 in email/common.ftl.

I added the else clause that you suggest and will see what happens.

-Dave

0
Avatar
Permanently deleted user

The additional else clause made no difference.

-Dave

0
Avatar
Permanently deleted user

Dave,

OK. At least it is consistent with the code.
Unfortunately right now we are busy with Eluru 6.0 release, so I'll try to reproduce the bug a bit later.
Do all other scripts in FreeMarker work correctly?


---
Maxim

0
Avatar
Permanently deleted user

Hi Dave,

I finally looked at the issue closely and found that TeamCity reports triggered information by default. Please check your .dist files, e.g. build_started.ftl.dist.
The exect expression uses TriggeredBy.isTriggeredByUser() method:
<#if build.triggeredBy.triggeredByUser>(triggered by ${build.triggeredBy.user.descriptiveName})</#if>

You can simply remove your .ftl files and .dist files replace them automatically (after restart).

---
Maxim

0
Avatar
Permanently deleted user

maxim.podkolzine wrote:

Hi Dave,

I finally looked at the issue closely and found that TeamCity reports triggered information by default. Please check your .dist files, e.g. build_started.ftl.dist.
The exect expression uses TriggeredBy.isTriggeredByUser() method:
<#if build.triggeredBy.triggeredByUser>(triggered by ${build.triggeredBy.user.descriptiveName})</#if>

You can simply remove your .ftl files and .dist files replace them automatically (after restart).

---
Maxim


That expression is only in "build_started" email template. We don't use that template at all. We only use "build_successful" and "build_failed" email. That expression is not in either of those templates. However, this helps me correct the common.ftl macro that I created.

It is now set this way:
<#macro triggered_by build>
  <#-- @ftlvariable name="build" type="jetbrains.buildServer.serverSide.SBuild" -->
  <#if build.triggeredBy.triggeredByUser>
    <div>Triggered by: ${build.triggeredBy.user.descriptiveName}</div>
  </#if>
</#macro>

I'm assuming that this should add a "Triggered by: <username>" line in email if the build is started manually by a TeamCity user and there will be no triggered-by line if the build is started automatically by TeamCity. This is close enough to what I am looking for.

I will report if this works.

-Dave

0
Avatar
Permanently deleted user

Okay. This works as I expected. i.e.: when a manual build is launched by TeamCity user, the Triggered by line appears in email. If TeamCity launches a build automatically, no triggered-by line appears in email. This is an acceptable solution to this problem.

0
Avatar
Permanently deleted user

OK, Dave, thank you.

---
Maxim

0

Please sign in to leave a comment.