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.
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.
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.
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.
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.
Step 7: In the Post-build Actions section click on “Add post-build action” dropdown.
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:
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:
Step 9: Click on 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…
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.
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.
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.
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.
Step 14: Once ready click on Build to start the job.
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:
Step 16: Navigating to the next page you can check out the console output by clicking on 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!
Swell!
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.
i want to display only xlsx file content as body of mail
Hope Soma has answered your question. 🙂
Cheers
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 “/”
That’s a good one Soma. Thanks for helping.
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 ??
Hi Mickey,
Is this issue resolved?
Nothing is coming in my mail
Hi Ankita,
Are you doing this from home or office? Something could be wrong with your SMTP. You need to contact your Admin.
Cheers
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..
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?
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
this didn’t work for me
I want to send an excel file to a remotedly triggered job as an attachment
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.