How can one use ansicolor with email-ext in Jenkins via JELLY_SCRIPT?
Asked Answered
S

0

8

I have a Jenkins server with using the plugins ansicolor and email-ext. Jenkins runs scripts with ANSI escaped text which is properly being converted to color-coded HTML on the console output of the Jenkins web GUI.

Email-ext is being used to send out emails which include the log file using the a Jelly script template which was based on the built in html template (ie Default Content box has value ${JELLY_SCRIPT,template="html_modified"}). However, the log data in the email is not color coded, even though the email Content Type is set to HTML.

According to a Jelly tip in the email-ext docs, one can

...get object of other plugin actions by querying build actions like: ${it.getAction('hudson.plugins.fitnesse.FitnesseResultsAction')}

I think this can be used to solve the following problem, but I'm not sure how. How can one use the it.getAction() function in a Jelly template to make use of ansicolor's HTML emitter? I've tried looking at the source to find what "action" I could use in the Jelly tip example.

Note that it appears the log data being acquired in the built-in html template uses build.getLog(100) which, for some reason, does not provide the original ANSI-escaped log text. If such text was passed through ansicolor, it would not get HTML-tagged since there are no ANSI tags to convert. Thus, the loop in the html template should pull from the log file.

Here is the html template snippet I'd like to modify to

  1. Pull log from file instead of build.getLog(100)
  2. Pass text through ansicolor to make it into pretty HTML

<TABLE width="100%" cellpadding="0" cellspacing="0">
  <TR>
    <TD class="bg1">
      <A href="${rooturl}${build.url}">${rooturl}${build.url}><B>CONSOLE OUTPUT</B></A>
    </TD>
  </TR>
  <j:forEach var="line" items="${build.getLog(100)}">
    <TR>
      <TD class="console">${line}</TD>
    </TR>
  </j:forEach>
</TABLE>
Schaub answered 27/1, 2015 at 22:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.