Editable Email Notification

254 views
Skip to first unread message

jer...@bodycad.com

unread,
Jun 3, 2016, 1:12:35 PM6/3/16
to Jenkins Users
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:


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 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;"

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>

jer...@bodycad.com

unread,
Jun 3, 2016, 1:24:42 PM6/3/16
to Jenkins Users
Sorry for the polution, but just realized my notepad++ didn't reload the log after Jenkins wrote to it. I have a new errors, but I checked the file path and the file are there?!? maybe it doesn't support multiple file anymore?!!

SEVERE: Groovy Template file [CieTemplate1.template, EmailTemplate2.template] was not found in $JENKINS_HOME/email-templates.
Jun 03, 2016 12:34:55 PM jenkins.model.PeepholePermalink updateCache

$JENKINS_HOME is c:\Jenkins
and the file are indeed into $JENKINS_HOME/email-templates
c:\Jenkins\email-templates\CieTemplate1.template, 
c:\Jenkins\email-templates\EmailTemplate2.template

humm permission are right and can be R and even write for the user jenkins service run under

jer...@bodycad.com

unread,
Jun 3, 2016, 1:50:27 PM6/3/16
to Jenkins Users
Finaly found the problem, the password into the Extended E-mail Notification plugin was not set properly, but was into the E-mail Notification so the test email was going out but not the one from template. The error about not found was due to env var and reboot Jenkins.

Why is Extended need another SMTP config and the why does the config is hidden into advanced...

I updated while changing machine, so the email password hash and enc key were regen.

Sorry for the noise. But I would still love to known if anybody have a good way to use 2 template without env injection and the -Dhudson.model.ParametersAction.safeParameters= into jenkins config.

Slide

unread,
Jun 3, 2016, 2:43:34 PM6/3/16
to Jenkins Users
E-mail Notification is for the Mailer plugin configuration.

--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/60d98781-464f-4929-a562-73dcaf313d72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages