Hi,
After moving to Jenkins 2.7 (from 1.5.x) I got everything running except 
the *editable email notification* the way we used to do it. We were using 2 
template file per project, 1 that define a few env variables first then the 
second one to generate the email. So we have different project that may 
choose a different cie template (1st one). So we generate 1 file per cie 
with minimum variables definitions (see below). I have the following email 
plugin installed:

Email Extension Template Plugin 
<https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+Template+Plugin>
Email Extension Plugin 
<http://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin>


My email project default content is set as follow:
${SCRIPT, template="CieTemplate1.template"}
${SCRIPT, template="EmailTemplate2.template"}

At first I had problem with security and the environment injection from 
template files. 

*Jun 03, 2016 10:25:17 AM hudson.model.ParametersAction filter*
*WARNING: Skipped parameter `EMAIL_CIE_LOGO` as it is undefined on `CAD`. 
Set `-Dhudson.model.ParametersAction.keepUndefinedParameters`=true to allow 
undefined parameters to be injected as environment variables or 
`-Dhudson.model.ParametersAction.safeParameters=[comma-separated list]` to 
whitelist specific parameter names, even though it represents a security 
breach*

So I added the following options into jenkins.xml (I'm on Windows):
-Dhudson.model.ParametersAction.safeParameters=EMAIL_CIE_COLOR,EMAIL_CIE_LOGO

But now it doesn't complain (nothing into the jenkins.err.log), but the 
email is not received (the test email go through and get received into 
Jenkins config, so the smtp settings is right).

Anybody have an idea of what is wrong? Or is there a better way to do this 
now?

*CieTemplate1.template*

<!-- Custom Variables -->
<%
import hudson.model.*

def style_cie_color = "#77278B"
def cie_logo = "https://www.mywebsite.com/images/Logo.png";

def pa = new ParametersAction(
[
new StringParameterValue("EMAIL_CIE_COLOR", style_cie_color),
new StringParameterValue("EMAIL_CIE_LOGO", cie_logo)
])

def build = Thread.currentThread().executable
build.addAction(pa)

%>

*EmailTemplate2.template*

<%
import  hudson.Util
import  hudson.Functions
import  hudson.model.Result;
import  hudson.matrix.MatrixBuild
import  hudson.matrix.MatrixRun
import  hudson.matrix.MatrixConfiguration
import  hudson.matrix.MatrixProject
import  hudson.matrix.Combination
%>

<!-- Extract previous template Variables -->
<%
def env = build.environment

style_cie_color = env.EMAIL_CIE_COLOR
cie_logo = env.EMAIL_CIE_LOGO
%>

<!-- Local variables -->
<%
style_default = "font-family:Verdana,Helvetica,sans serif; font-size:11px; 
color:black;"
style_header = "color: black;"
style_bg1 = "color:white; background-color:" + style_cie_color + "; 
font-size:120%;"
style_bg2 = "color:#666666; background-color:white; font-size:110%; 
margin-left: 2px; margin-right: 2px;"
style_bg3 = "color: black; background-color:white;"
style_tr = "border: 1px solid " + style_cie_color + ";"
style_failure = "color: red;"
style_success = "color: green;"
style_unstable = "color: yellow;"
style_console = "font-family:Courier New;"
result_img = "https://www.mywebsite.com/images/";

if(build.result == Result.SUCCESS) 
{
result_img += "success.small.png"
build_style = style_success;
} 
else if (build.result == Result.FAILURE) 
{
result_img += "error.small.png"
build_style = style_failure;
} 
else 
{
result_img += "warning.small.png"
build_style = style_unstable;
}
%>

<BODY style="${style_default}">

<!-- Main info -->
<TABLE>
<TR>
<TD valign="right"><IMG SRC="${cie_logo}" /></TD>
</TR>
<TR>
<TD align="right"><IMG SRC="${result_img}" /></TD>
<TD valign="center"><B style="font-size: 200%;">BUILD 
${build.result}</B></TD>
</TR>
<TR>
<TD>Build URL</TD>
<TD><A href="${rooturl}${build.url}">${rooturl}${build.url}</A></TD>
</TR>
<TR>
<TD>Project:</TD>
<TD>${project.name}</TD></TR>
<TR>
<TD>Date of build:</TD>
<TD>${it.timestampString}</TD>
</TR>
<TR>
<TD>Build duration:</TD>
<TD>${build.durationString}</TD>
</TR>
</TABLE>
<BR/>
<!-- ... -->

</BODY>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/619526a2-6bfd-47ad-9f4f-568f7ba0c460%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to