Include artifacts in Team City E-Mail Notifier

If you have admin access to teamcity server, you can easily update the default email notification template to include artifacts of a build. This is how I did it.

Step1: Navigate to Team City _notifications folder. (in my case it was C:\ProgramData\JetBrains\TeamCity\config\_notifications\email)

Step2: Add below lines to build_failed.ftl and build_successful.ftl

<p>Build artifacts:</p>
  <#list build.artifactsDirectory.listFiles() as file>
    <a href="${webLinks.getDownloadArtefactUrl(build.buildTypeExternalId, build.buildId, file.name)}">${file.name}</a> (${file.length()}B)<br/>
  </#list>
Step3: Push a build and check your email 😉
This is how build_successful.ftl looked like after the addition.

<#– Uses FreeMarker template syntax, template guide can be found at http://freemarker.org/docs/dgui.html –>

<#import “common.ftl” as common>
<#import “responsibility.ftl” as resp>

<#global subject>[<@common.subjMarker/>, SUCCESSFUL] Build ${project.fullName} :: ${buildType.name} <@common.short_build_info build/></#global>

<#global body>Build ${project.fullName} :: ${buildType.name} <@common.short_build_info build/> successful ${var.buildShortStatusDescription}.
<@resp.buildTypeInvestigation buildType true/>
Agent: ${agentName}
Build results: ${link.buildResultsLink}

${var.buildCompilationErrors}${var.buildFailedTestsErrors}${var.buildChanges}
<@common.footer/></#global>

<#global bodyHtml>

Build ${project.fullName?html} :: ${buildType.name?html} successful
${var.buildShortStatusDescription}

<p>Build artifacts:</p>
<#list build.artifactsDirectory.listFiles() as file>
<a href=”${webLinks.getDownloadArtefactUrl(build.buildTypeExternalId, build.buildId, file.name)}”>${file.name}</a> (${file.length()}B)<br/>
</#list>
<@common.build_agent build/>
<@common.build_comment build/>
<br>
<@common.build_changes var.changesBean/>
<@common.compilation_errors var.compilationBean/>
<@common.test_errors var.failedTestsBean/>
<@common.footerHtml/>
</div>
</#global>

and here is a sample email containing build artifacts.

Build artifacts:
.teamcity (0B)
Project Report.pdf (2992569B)
Agent: Agent007

Link to TeamCity Documentation

Advertisements