How to Mail Reports Through Jenkins | Configuring Email Notifications

This bit focuses on how to mail reports through Jenkins. We will see how to configure email notifications so that every time you run a job, emails get sent out to your team. Wouldn’t that be great?

Jenkins makes a lot of things easy. Not only does it provide a platform to run a build without getting into the technical aspects of it but it also ensures a proper completion of a project cycle which basically ends with you sending out a report to your peers. This is where our How to Mail Reports through Jenkins tutorial will come into the picture.

jenkins meme

We are going to make use of the Editable Email Notification plugin in order to achieve this.

Let’s just quickly see how to mail reports through Jenkins using a step by step tutorial.

Steps on How to Mail Reports Through Jenkins

Step 1: The first step is to open Jenkins of course and navigate to your dashboard where you will have the Manage Jenkins option. Click on it.

manage jenkins option

Step 2: In the next screen scroll down to the part that reads “Manage Plugins”.

Step 3: Click on the “Available” tab and then on the Filter textbox to check if the Email Extension Plugin is present or not.

NOTE: In case you don’t find it there, check the “Installed” Tab to see if it is already installed on your Jenkins.

install without restart

Step 4: Once you find it click on Install without restart.

Once the installation finishes, the plugin will basically be creating a separate box in your Post-Build Actions section that you can leverage to use all the generic mail functionality.

Step 5: Navigate to your project from your Dashboard. Then click on Configure.

click on configure option

Post Build Actions

Step 6: In the next screen click on the Post-build Actions tab. Or you can simply scroll down to the bottom of the screen.

post build actions jenkins

Step 7: In the Post-build Actions section click on “Add post-build action” dropdown.

 

add post build action

It will flare a dropdown of options.

Step 8: Look for the option that says Editable Email Notification. When you find it just click on it:

click on editable email notification option

On clicking on it you will notice a new plugin box being displayed in the Post-build actions section. It might look something like this:

editable email notifia

Step 9: Click on Advanced Settings…

advanced settings

Doing so will open some more textboxes. Triggers are nothing but instances where you wish to send out the email.

Step 10: Click on Add Trigger…

click on add trigger

Step 11: Select when you wish to send out the report. I want the report after build so I am going to select Script – After build.

Step 12: Click on Advanced… button located in the Script – After Build section.

Notice every aspect of the plugin. That’s the place from where you can define who to send the emails to, what to add as the content, what should be the Subject etc. Go ahead and play around with it.

I am gonna just leave everything as is, except the recipient list, of course, where I will put an email ID just to check if reports are indeed being sent out.

emails-in-plugin

 

NOTE: As mentioned in the image above, you can add as many emails as you want. Just separate them by commas.

In the subject or default content textboxes you can customize things with your own custom messages. I am just gonna leave things blank and move on to the part that matters the most to me right now – the Attachments section.

Attachment of Reports

Step 9: Navigate back to your Workspace and check what’s the path of your reports.

target folder jenkins

In my case here, the path is basically:

target/extent-report/

where all my .xlsx files are located.

If you need all the .xlsx files, you can simply mention it like this:

target/extent-report/*.xlsx

which basically means all the files that have the extension .xlsx.

Step 10: I am gonna just go ahead and add the above in the attachments textbox:

You can provide your very own location of the report here. Just make sure the extension you want is right. (In case of Extent Report provide .html etc.)

NOTE: If you do not want to attach a build log to your mail and just want the report part you can select “Do Not Attach Build Log” option from the dropdown of Attach Build Log like this:

Step 12: Once done you can simply click on Apply then Save to proceed back to your project.

apply then save

Time to run it.

Execution of your Job

Next screen will take you to your project once again from where you can run your job to check whether or not the reports are being generated.

Step 13: Click on Build with Parameters which will take you to the part from where you can enter your parameters.

build with parameters

Step 14: Once ready click on Build to start the job.

click on build jenkins

NOTE: Of course this will be different for your project.

Step 15: The build will basically start with that. You can choose to check out the build information by clicking here:

build info jenkins

Step 16: Navigating to the next page you can check out the console output by clicking on Console Output.

console output

Now we wait….

For the execution of our job.

Alright with that the report might have been sent out to my email ID. I will just go and quickly check!

mail received

Swell!

mail dropped for report

Checking for the report now. Yep! There!

Now that you know How to Mail Reports Through Jenkins start mailing the reports in an automated fashion.

Check out more cool stuff from DITD.

Scottshak

Poet. Author. Blogger. Screenwriter. Director. Editor. Software Engineer. Author of "Songs of a Ruin" and proud owner of four websites and two production houses. Also, one of the geekiest Test Automation Engineers based in Ahmedabad.

You may also like...

14 Responses

  1. harish says:

    i want to display only xlsx file content as body of mail

  2. Soma Sekhar says:

    Follow below steps it will work .

    jenkins -> configuration -> Editable Email Notification

    Content Type : HTML(text/html)

    Default Content: ${FILE,path=”build/reports/tests/test/index.html”}

    Don’t start file path with “/”

  3. Mickey says:

    I’m getting double attachments in my mail.. I gave *.xslx in global ,den for failure (error reports) and no attachments for success.. can u say whr us ut gng wrng ??

  4. Ankita says:

    Nothing is coming in my mail

  5. Ankita says:

    home…
    javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
    535 5.7.8 https://support.google.com/mail/?p=BadCredentials o15sm2941831pjp.41 – gsmtp

    this is coming..

    • Scottshak says:

      This looks something related to credentials. This could happen owing to wrong username or password?

      Or if you are sure they are correct, maybe Gmail is treating Jenkins’ signing method as insecure. I am not sure why though. :/

      Can you try this using a different email?

  6. Ankit says:

    I want display specific file data as a content. I tried with ${FILE,path=”$BUILD_NUMBER/filename.property”} in this case I got the content like 21/filename.property
    and also with
    ${FILE,path=”$WORKSPACE/$BUILD_NUMBER/filename.property”}
    in this case I got the /var/lib/jenkins/workspace/21/filename.property

    Can you please help me to achieve this

  7. Tania says:

    this didn’t work for me

  8. LOKESH says:

    I want to send an excel file to a remotedly triggered job as an attachment

  9. Madhavan says:

    Hi, Is it possible to send the entire target folder like zip ? .I can able to send the html file but I need to send entire output folder in the attachment like zip.

Leave a Reply