FTL Access Artifacts
There doesn't seem to be a lot of documentation on how to use the FTL's for customizing notifications. I've poured over google and this forum for any references but haven't had much luck.
Does anyone know how to reference the artifacts in a build? One of the artifacts generated is an HTML file that I would like to include in the email as a link. Any help is much appreciated.
Thanks
Please sign in to leave a comment.
I've actually came here looking for the exact same functionality. I found the getArtifacts function which should provide the required data but the problem is this function requires a complex argument (BuildArtifactsViewMode) which I don't really understand how to pass.
It should look something like -
<#list build.getArtifacts(VIEW_DEFAULT) as artifact>
do something with artifact
</#list>
Any help will be appreciated.
I ended up writing a plug-in to extend the notification template model
// // MyCompanyNotifications.java // // This class is a TeamCity plug-in for extending the Freemarker root model so // that we can incorporate the mycompanybuild.html file as part of the email we // send out. // // We tried using the Freemarker <#include> item, but as of TeamCity 8 it is // restricted to including files in the notifications template directory and // cannot access artifact files. // // The TeamCity Freemarker files for email are located on the server in the // directory: // // D:\ProgramData\JetBrains\TeamCity\config\_notifications\email // // To use this, modify the .ftl file(s) to contain this line: // // ${mycompanynotifications.getFileContents( build.artifactsDirectory + "\\mycompanybuild.html" )} // package mycompany.teamcity.plugins; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.FileInputStream; import java.lang.Exception; import java.lang.StringBuilder; import java.util.HashMap; import java.util.Map; import jetbrains.buildServer.notification.NotificationContext; import jetbrains.buildServer.notification.TemplateProcessor; //import jetbrains.buildServer.serverSide.SBuildServer; import org.jetbrains.annotations.NotNull; //import freemarker.ext.beans.BeansWrapper; public class MyCompanyNotifications implements TemplateProcessor { public static class MyCompanyReadFile { public String getFileContents( String fileName ) { try { BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream( fileName ), "UTF-16" ) ); String line = null; StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty( "line.separator" ); while( ( line = reader.readLine() ) != null ) { stringBuilder.append( line ); stringBuilder.append( ls ); } return stringBuilder.toString(); } catch( Exception e ) { return "Can't read " + fileName; } } } @NotNull public Map< String, Object > fillModel( @NotNull NotificationContext context ) { Map< String, Object > model = new HashMap< String, Object >(); MyCompanyReadFile fileReader = new MyCompanyReadFile(); model.put( "mycompanynotifications", fileReader ); return model; } }And here is a copy of the Windows Batch file to build it:
Attachment(s):
MyCompanyNotifications.java.zip
MyCompanyNotifications_Build.bat.zip
Hi Brett,
Thank you for sharing your plugin! We've added a link to this thread to the related feature request: https://youtrack.jetbrains.com/issue/TW-7318.