0
votes

I am using Jenkins 2.46.3 on Redhat Linux 5.10 and trying to change email subject and content and need help how to write a groovy script in pre-send section of Jenkins when using Email-ext plugin to send emails as post-build action.

To test when below lines are in pre-send script section nothing happens ( maybe they are wrong) as emails are still with default subject and header. There is nothing in Jenkins.log either so unable to find what is wrong.

msg.addHeader("Importance", "High"); 
msg.addSubject("Test message - package built successfully");

If someone can give a few liners script to modify msg variable that I can specify in pre-send section for testing purpose will help me understanding how to make it work.

Thanks in advance, Sachin

P.S. Not sure if Groovy plugin should be installed for pre-send script to work though installing it didn't help either.

1

1 Answers

1
votes

As for msg.addSubject, wrong method was used. the correct one is:

msg.setSubject("Test message - package built successfully");

You can reffer to official oracle documentation to see which methods and parameters are supported by msg: http://docs.oracle.com/javaee/6/api/javax/mail/internet/MimeMessage.html

msg.addHeader works correctly in your example. I have just tested it in outlook and it worked.

P.S. Also it may require to import packages like this at the start of the script:

import javax.mail.Message
import javax.mail.internet.InternetAddress

Best Regards,

Jon