How can I replace text in my log using Jenkins email-ext

66 views
Skip to first unread message

Daniel Barker

unread,
Nov 27, 2013, 1:52:25 PM11/27/13
to jenkin...@googlegroups.com

At work, we use a social networking system based on Jive. We have the ability to email to the service, but it has sever limitations on what characters can be included. We currently manipulate the output via the actual programs we are running, but we want a plugin type solution for Jenkins. We need to be able to remove/replace characters like [, ], {, }, --, etc. We want to output the entire log or parts of it depending on the particular job. 


I have tried both the Jelly script and Groovy script methods, but neither seem to support the parts I need. In Jelly, I used fn:replace, and in Groovy, I tried to use a matcher. I haven't been able to figure out what the limitations are for these scripts with this extension or how to extend them if possible. 


I have thought about adding some functionality to the actual plugin or creating a new plugin that can do some pre-processing. The first option wouldn't be too hard, but it has obvious drawbacks within the bounds of modifying well-established, working code. The second option would require a great deal more effort for limited functionality. Any advice would be much appreciated. Thanks in advance.

Slide

unread,
Nov 27, 2013, 2:12:40 PM11/27/13
to jenkin...@googlegroups.com
Can you give examples of what you have tried? I would recommend using Groovy for sure, Jelly is painful at best. 


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Website: http://earl-of-code.com

Daniel Barker

unread,
Nov 27, 2013, 4:28:03 PM11/27/13
to jenkin...@googlegroups.com
Hey Slide,

Thanks for the rapid response.

This is horribly embarrassing. I tried to delay posting here for several days while I worked on this on and off, but I finally got it to work. It essentially worked exactly as it was supposed to. I will post my solution for Groovy below and one gotcha.

The below code works correctly with the import. I haven't tried it without the import, but I was under the impression based off of previous research that imports didn't work. There is a gotcha that caused me a problem. The line "formatLine(line)" will not work in place of "${formatLine(line)}" regardless of how the angle bracket and percent signs are placed. I'm not really sure why it won't work, but it didn't for this.

<% import java.util.regex.*; %>

<%def formatLine(line)
{
    braceMatcher = (line =~ /\[/);
    line = braceMatcher.replaceAll("");

    braceMatcher = (line =~ /\]/);
    line = braceMatcher.replaceAll("");
} %>

<% if(build.result==hudson.model.Result.SUCCESS) { %>
CONSOLE OUTPUT
<%     build.getLog(1000).each() { line -> %>
         ${formatLine(line)}
<%     } %>


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/ABg9iqvDSVM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.

Slide

unread,
Nov 27, 2013, 4:30:32 PM11/27/13
to jenkin...@googlegroups.com
Hi Dan,

Why break out of the groovy code at that point? Why not just stay in groovy mode?

<% if(build.result==hudson.model.Result.SUCCESS) { %>
CONSOLE OUTPUT
<%     build.getLog(1000).each() { line ->
              formatLine(line)
          }%>

Does that not work?

Thanks,

slide

Daniel Beck

unread,
Nov 27, 2013, 4:34:54 PM11/27/13
to jenkin...@googlegroups.com

On 27.11.2013, at 22:30, Slide <slide...@gmail.com> wrote:

> formatLine(line)

Missing println probably.

Daniel Barker

unread,
Nov 27, 2013, 4:40:44 PM11/27/13
to jenkin...@googlegroups.com
That's what I had been trying, but it just produces blank output. I just modified my code and tried again. It still isn't printing anything that way. I haven't tried adding a println, but it didn't seem like that was necessary.

Slide

unread,
Nov 27, 2013, 4:42:23 PM11/27/13
to jenkin...@googlegroups.com
I think that's basically what the syntax you are using now will do. It outputs the value of the evaluation, so if you are just calling the method, you aren't printing anything, just evaluating and throwing away the result. By ending the groovy context and starting an output/text context, you are outputting the result of the eval.

Daniel Barker

unread,
Nov 27, 2013, 4:48:57 PM11/27/13
to jenkin...@googlegroups.com
I think it all just clicked today how this syntax works. The syntax was a bit confusing at first, and it didn't help that I bounced between Jelly and Groovy for awhile trying to learn both enough to make a determination as to which is better. Groovy seems to be better from what I have learned. I think things will go much more smoothly, and I'll post my experiences up somewhere to help future Googlers.

The println works perfectly, by-the-way.

I appreciate the fast input and guidance.

Slide

unread,
Nov 27, 2013, 4:53:04 PM11/27/13
to jenkin...@googlegroups.com
Honestly, I wish Jelly would die a horrible death. I've debugged so many issues trying to do stuff in Jelly, I really wish I could just rip it out of email-ext. I've been pondering writing a converter that converts Jelly templates to Groovy templates and doing just that, but only in my most frustrated of times ;-)

Glad its working for you.

slide

Daniel Barker

unread,
Nov 27, 2013, 5:17:36 PM11/27/13
to jenkin...@googlegroups.com

I concur. That would be a noble endeavor. However, in the meantime perhaps something could be added to the docs stating a preference for Groovy. It would certainly help noobs like me to focus on only one at the outset.

Reply all
Reply to author
Forward
0 new messages