Jenkins pass build parameters to email-ext template

Rnet picture Rnet · Jun 27, 2013 · Viewed 7.2k times · Source

How can I pass the build parameters to the email-ext jelly template? Before making some builds I would like to put a different custom message/some announcement/non-code changes, decisions etc. I'm thinking of putting this as a build parameter so that I'm presented with a screen prompting me to enter the message if I'm going to build manually.

Edit: I found a solution, the build params are available as Env variables, I have this code to access Env variables:

   <j:set var="buildenv" value="${build.getEnvironment(listener)}"/>
   <j:set var="customMsg" value="${buildenv.get('customMsg')}"/>
   ${customMsg}

Answer

Josh Unger picture Josh Unger · Jun 28, 2013

Switch to the email-ext groovy email templates.

Then, copy the sample groovy-html.template and customize it by adding the following script -

<%
  def parametersAction = build.getAction(ParametersAction.class)

  if (parametersAction != null)
  {
    for (p in parametersAction.parameters)
    {
      %><%=p.name%>=<%=p.value%><br/><%
    }                                               
  }
%>

Take a look at the hudson.model.ParametersAction class.