Welcome to the Question and Answer site for Software Testing Professionals

You can get your queries resolved from Software Testing Professionals.

Ask a Question

Get answers and give answers to questions from other members.

View All Questions

Get votes and earn points to build your reputation in community.

View Hot Questions

0
Is there any way to modify email subject and the body in Jenkins using my automated test script written in Java?

Solved 2 Answers 730 Views
0 2
I am currently using Jenkins as my CI tool. After my automation scripts are executed it sends a console log as an email to a specific set of recipients.

I want email body and the subject to be customized as per my requirements.

I am using Java as my programming language. Is there any way to override this email subject and body using Java?

2 Answers

1
Best answer
1

Changing email body programmatically is possible now.

  • You can go to Manage Jenkins > Configure System and set Default Content as

           ${FILE,path="email-body.html"}

           under Extended E-mail Notification area.


Now, you just have to generate email-body.html file programmatically directly under your workspace root.

Sample code:

@After
    public void writeLog() throws IOException {
        File file = new File("email-body.html");
        StringBuilder htmlBuilder = new StringBuilder();
        htmlBuilder.append("<html>");
        htmlBuilder.append("<head><title>Hello World</title></head>");
        htmlBuilder.append("<body><p>Look at my body!</p></body>");
        htmlBuilder.append("</html>");
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
        bufferedWriter.write(htmlBuilder.toString());
        bufferedWriter.close();

    }

Also, make sure that default content type is set to HTML.

answered by (192 points)
edited by
0
0
No! Because, email subject and email content are set using an environment variable. Environment variables can not be changed throughout the process once set.

So, you can either write a custom program to send an email or you can create an attachment which will be attached to your email.
answered by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

We have resolved 1.2k+ Software Testing queries!

Software Testing Board Weekly update

We will send you handpicked questions that you would love to answer.

View previous campaigns.

Top Contributors

...