Skip to content

Instantly share code, notes, and snippets.

@slide
Created July 23, 2018 19:14
Show Gist options
  • Save slide/81bfadb06754bfc99de00bc459f87709 to your computer and use it in GitHub Desktop.
Save slide/81bfadb06754bfc99de00bc459f87709 to your computer and use it in GitHub Desktop.
@NonCPS
def createBody(build, env, changeSets, builds, failedBuilds) {
def text = '''
<html>
<style>
BODY, TABLE, TD, TH, P {
font-family:Verdana,Helvetica,sans serif;
font-size:11px;
color:black;
}
h1 { color:black; }
h2 { color:black; }
h3 { color:black; }
TD.bg1 { color:white; background-color:#0000C0; font-size:120% }
TD.bg2 { color:white; background-color:#4040FF; font-size:110% }
TD.bg3 { color:white; background-color:#8080FF; }
TD.test_passed { color:blue; }
TD.test_failed { color:red; }
pre { display: inline }
</style>
<body>
<table width="100%">
<tr><td class="bg1" colspan="2"><b>BUILDS</b></td></tr>
<% builds.each { k,v -> %>
<tr>
<td width="5%">
<% if(failedBuilds.contains(k)) { %>
<img src="${env.JENKINS_URL}static/e59dfe28/images/16x16/red.gif" />
<% } else { %>
<img src="${env.JENKINS_URL}static/e59dfe28/images/16x16/blue.gif" />
<% } %>
</td>
<td align="left"><%= k %></td>
</tr>
<% } %>
</table>
<br/>
<% if(changeLogSets != null) { %>
<!-- CHANGE SET -->
<table width="100%">
<tr><td class="bg1" colspan="2"><b>CHANGES</b></td></tr>
<% changeLogSets.each { changeSet ->
changeSet.items.each { ci -> %>
<tr>
<td colspan="2" class="bg2">Revision <b><%= ci.commitId %></b> by
<b><%= ci.author %>: <%= ci.msg %></b>
</td>
</tr>
<% ci.affectedPaths.each { p -> %>
<tr>
<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= p %></td>
</tr>
<% } %>
<% } %> <!-- changeSet.items.each -- >
<% } %>
<% if(changeLogSets.isEmpty()) { %>
<tr><td colspan="2">No Changes</td></tr>
<% } %>
</table>
<br/>
<% } %>
</table>
<br/>
</body>
</html>
'''
def binding = [
'build' : build,
'changeLogSets' : changeSets,
'builds' : builds,
'failedBuilds' : failedBuilds,
'env' : env
]
def engine = new groovy.text.SimpleTemplateEngine()
def template = engine.createTemplate(text).make(binding)
return template.toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment