Using Freemarker templates
Hi.
I need to configure email notofication templates. As I understood, here are all pre-defined objects I can use in templates
http://confluence.jetbrains.net/display/TCD5/Customizing+Notifications+(in+TeamCity+5.1)
Here is the list:
<#-- @ftlvariable name="project" type="jetbrains.buildServer.serverSide.SProject" -->
<#-- @ftlvariable name="buildType" type="jetbrains.buildServer.serverSide.SBuildType" -->
<#-- @ftlvariable name="build" type="jetbrains.buildServer.serverSide.SBuild" -->
<#-- @ftlvariable name="agentName" type="java.lang.String" -->
<#-- @ftlvariable name="buildServer" type="jetbrains.buildServer.serverSide.SBuildServer" -->
<#-- @ftlvariable name="webLinks" type="jetbrains.buildServer.serverSide.WebLinks" -->
<#-- @ftlvariable name="var.buildFailedTestsErrors" type="java.lang.String" -->
<#-- @ftlvariable name="var.buildShortStatusDescription" type="java.lang.String" -->
<#-- @ftlvariable name="var.buildChanges" type="java.lang.String" -->
<#-- @ftlvariable name="var.buildCompilationErrors" type="java.lang.String" -->
<#-- @ftlvariable name="link.editNotificationsLink" type="java.lang.String" -->
<#-- @ftlvariable name="link.buildResultsLink" type="java.lang.String" -->
<#-- @ftlvariable name="link.buildChangesLink" type="java.lang.String" -->
<#-- @ftlvariable name="responsibility" type="jetbrains.buildServer.responsibility.ResponsibilityEntry" -->
<#-- @ftlvariable name="oldResponsibility" type="jetbrains.buildServer.responsibility.ResponsibilityEntry" -->
So, according to API http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/SBuild.html#getBuildProblems()
I can type ${build.buildProblems}, and I should get the result. But instead I get WARN - .notification.FreeMarkerHelper - Expression build.buildProblems is undefined on line 15, column 3 in email/build_failed.ftl.
Can anybody point me to the solution?
Thanks.
Please sign in to leave a comment.
Hi Alex,
Could you please post the full build_failed.ftl script here.
Do other methods of ${build} work? Like getName or getBuildId?
---
Maxim
Hi.
Yes, they seem to be working ok.
Could you please help me in this issue?:
getCommitters
UserSet<SUser> getCommitters(SelectPrevBuildPolicy policy)
Parameters:
policy - can be one of the two kinds:
SelectPrevBuildPolicy.SINCE_LAST_BUILD - all modifications made since previous running build
SelectPrevBuildPolicy.SINCE_LAST_SUCCESSFULLY_FINISHED_BUILD - all modifications made since previous successfully finished build
I want to obtain all users that made commits.
So I should call ${build.committers(...)}, but what next?
I have to pass enum like a parameter, but how can I do this?
simple ${build.committers(SelectPrevBuildPolicy.SINCE_LAST_SUCCESSFULLY_FINISHED_BUILD)} doesn't work.
Here is my ftl.
<@common.footer/></#global>
<#global bodyHtml>
<div>
<div>
Build <i>${project.name}::${buildType.name} <a href='${link.buildResultsLink}'>#${build.buildNumber}</a></i> failed
${var.buildShortStatusDescription}
</div>
<@common.build_agent build/>
<@common.build_comment build/>
<br>
<div>a</div>
<#-- @ftlvariable name="bean" type="jetbrains.buildServer.vcs.SelectPrevBuildPolicy" -->
<#list build.revisions as revision>
<div>Revision #: ${revision.revisionDisplayName}</div>
<br>
</#list>
${build.committers("SINCE_LAST_SUCCESSFULLY_FINISHED_BUILD")}
<div>b</div>
${build.committers("bean.SINCE_LAST_SUCCESSFULLY_FINISHED_BUILD")}
</br>
<div>Following errors occured: </div>
<#list build.buildLog.errorMessages as message>
<div>${message.text}</div>
<br>
</#list>
<@common.build_changes var.changesBean/>
<@common.compilation_errors var.compilationBean/>
<@common.test_errors var.failedTestsBean/>
<@common.footerHtml/>
</div>
</#global>
Hi,
FreeMarker supports invocation of any method, not just getters. See the example in your common.ftl file:
${webLinks.getViewChangesUrl(bean.build)}
---
Maxim
Ok, but
field.SelectPrevBuildPolicy is not referenced as for example jetbrains.buildServer.serverSide.SBuild can be accessed as build.
How can I reference other class, for example Enum jetbrains.buildServer.vcs.SelectPrevBuildPolicy? I need jetbrains.buildServer.vcs.SelectPrevBuildPolicy.
How in this case can I call method UserSet<SUser> getCommitters(SelectPrevBuildPolicy policy)?
Thanks.
Yes, I see the problem.
Unfortunately accessing enums and static methods is not that easy - you have to put the classes to the model. The details: http://freemarker.sourceforge.net/docs/pgui_misc_beanwrapper.html#jdk_15_enums
Template model extension is supported via TeamCity plugins, example can be found here: http://confluence.jetbrains.net/display/TCD5/Extending+Notification+Templates+Model
---
Maxim
Do I need to create plugin or there's another way to you have to put the classes to the model?
Thanks.
You need to create a plugin.