Hi All,
This post mainly is for those who have Selenium scripts running as part of their Jenkins Jobs & want to include these results within the main body of the Jenkins Emailable Notification.
Solution:-
1.For the Post Build Actions > Select Editable Email Notifications
2.If this option is not there as part of post build actions, the email-ext-plugin is needed to be installed on Jenkins. Go to https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin)
3.Select Content Type as HTML(text/plain)
4.In the Default Content section : remove $DEFAULT_CONTENT.Place the following code to inject your html report into the default content :-
${FILE,path=”relative path to html file”}
Eg: ${FILE,path=”MyWorkspace/MyProj/test-output/emailable-report.html”}
This will place the emailable-report.html content in your email body.
5.You can further choose the various trigger points to include the test report i.e on success, test failures (any) , unstable etc.
Hope this is of use to someone struggling out there and landed up here!
Cheers,
VJ
Great article,
Thanks. This helped me a lot. I had a hard time find such a simple thing as sending a simple test report in Jenkins!
Cheers,
Baubak
LikeLike
Glad it was of help 🙂 …. Cheers! 🙂
LikeLike
How to add dynamic report name in Eg: ${FILE,path=”MyWorkspace/MyProj/test-output/dynamicname.html”}
In my case report is generated with a different name after every run.
LikeLike
Does your report start with a particular sequence of characters? Probably you could try out a regular expression. It should be possible. Let me know if it works.
LikeLike
hi VJ
i am still stuck. i am not able to attach the report, i use your code.
please guide here.
thanks……
LikeLike
Hey! Sure can help you.
Tell me the whole path of your file & your workspace .
LikeLike
Path is : C:/Users/Automation/SVN/ADSS/java_adss_v2/target/chrome/emailable-report.html
${FILE,path=”C:/Users/Automation/SVN/ADSS/java_adss_v2/target/chrome/emailable-report.html”}
LikeLike
What is your Jenkins Workspace path??…
Basically you should configure your Jenkins Job in such a way that the Automation Workspace must be within your Jenkins Workspace.
Eg -E:\JenkinsSlave\workspace\Your_Automation_Workspace
\Your_Automation_Project
So your automation reports will be seen as :-
E:\JenkinsSlave\workspace\Your_Automation_Workspace
\Your_Automation_Project\target\chrome\emailable-report.html
Then you can attach the report using the relative path of the Jenkins workspace for the corresponding job.
Eg:-${FILE,path=”\Your_Automation_Project\target\chrome
\emailable-report.html”}
LikeLike
the code i m using in Default_content :
${FILE,path=”C:/Users/Automation/SVN/ADSS/java_adss_v2/target/chrome/emailable-report.html”}
Content_Type: HTML(text/html) other options are:
Default, PlainText(text/plain), both html amd plain text.
LikeLike
Hi
please reply. i am stuck
thanks….
LikeLike
hi VJ
1-> Jenkins workspace path is: C:\Program Files\Jenkins\workspace
my project path is: C:\Users\Automation\SVN\ADSS\java_adss_v2
now i copied my project in “jenkins/workspace”.
now the path is: C:\Program Files\Jenkins\workspace\ADSS_J\java_adss_v2_J
this path i m giving in Jenkins Default_Content as: ${FILE,path=”C:\Program Files\Jenkins\workspace\ADSS_J\java_adss_v2_J\emailable-report.html”}…
even i tried with {${FILE,path=”\ADSS_J\java_adss_v2_J\emailable-report.html”} in Default_Content.
but still its not working.
2->In Jenkins workspace i have folders with build names, i tried to attach a file from one of the folder, still it didnt work.
eg. ${FILE,path=”C:\Program Files\Jenkins\workspace\123demo\Always-15-1086240151.html”}. here 123demo is the build name.
3->what i get is ” ${FILE,path=”C:\Program Files\Jenkins\workspace\123demo\Always-15-1086240151.html”} ” in mail body, no attachment.
Please buddy tell me what to do. i have a deadline very soon.
Thanks
LikeLike
This is what you need to give as part of your mail body :-
${FILE,path=”Always-15-1086240151.html”}
i.e relative path from the Jenkins Job(in your case from 123demo).You need to exclude the job name as well
Also select content type as HTML (text/html).
Let me know if it works…
LikeLike
can u plz help out to send mail…
Content Type HTML
Default Subject
Default Content ${FILE,path=D:\Jenkins\Jenkinsproject\JenkinsPracties\emailable-report.html”}
LikeLike
Hi Suresh,
First things first… How are you triggering the selenium scripts? ….
Also the path you give must be relative to your jenkins workspace. Here you have given the absolute path…
LikeLike
Please see my previous post to understand how to ‘Mavenise’ your Selenium project :-
LikeLike
Hi
I am stuck when trying to send html report through email notification .
Jenkins workspace path is C:\jenkins\workspace\FinanceworksAutomation\development\software\pfw\main\Automation\FW_Automation_New\target\surefire-reports
I gave it as ${FILE,path=”target/surefire-reports/emailable-report.html”}
what is receive in email is
ERROR: File ‘target/surefire-reports/emailable-report.html’ does not exist
LikeLike
Path of the file must be relative to the project… so if your project name is “FinanceworksAutomation”, then try this out :-
${FILE,path=”FinanceworksAutomationdevelopment/software/pfw/main/Automation/FW_Automation_New/target/surefire-reports/emailable-report.html”}
LikeLike
Hey
Its been a full day now, and I havent got any success in getting Testng reports in email once the Jenkins Job run. I doubt if at all its possible because I have tried all possible ways
I configured Jenkins Job and here are the details of Editable Email Notification in Jenkins Job :
Default Content –
${FILE,path=”a/tests/target/surefire-reports/emailable-report.html”} – This is the path to my testng html file. The Jenkins Jobs workspace
starts with ws and complete path to the file from workspace is ws/a/tests/target/surefire-reports/emailable-report.html
Let me know if this path is not correct ? I though have tried all possible options here.
When I give the file path to Attachments field as – tech.core/tech.core.api.tests/target/surefire-reports/index.html
I do get an attachment with the email But that doesn’t contain any image. Also when I click the attachment, the report is highly distorted and no styling/css is applied on to it.
Let me know if it is possible to get Testng reports via email so that I can send these to stakeholders. I thought this to be a very very common requirement and did not
expected it to take so much time to resolve/configure.
I have high expectations to get an answer here !! Any help highly appreciated as its an urgent requirement at my end
thanks
LikeLike
Try out :-
${FILE,path=”tests/target/surefire-reports/emailable-report.html”
LikeLike
Thanks a lot! This helped a bunch. Had to struggle with Jenkins and company email settings before I could use this nut thanks, it really helped.
Also, if you can edit the post to specify that you don’t need to add the path to the project and workspace in the path, that’d be great.
LikeLike
Glad it helped :)… Yup will update the post when I find time.. Thanks for the feedback 🙂
LikeLike
Hi,
I have configured the extended email configurations under 1. Project configuration, 2. Global configuration & email template.Also, have configured email to trigger for all scenarios, configured the jenkins workspace same as project workspace as per your suggestion in previous posts.Have tried all the possible options of FILE paths as discussed in your blog. When i build the project, i receive mail notification only when build fails with build failure logs and for successful builds, i only get a notification with jenkins url without any attachments !!
i have run out of options and badly need you help.
LikeLike
Hi Srikanth,
I have a feeling you are going wrong with your configuration of the email notification. Firstly you need the ‘Email Extension Plugin’ & ‘Email Extension Template Plugin’
In editable email notification specific to each job do the following steps :-
1.Click on Advanced Settings.
2.Click on Add Trigger
3.Over there add a trigger, like Failure,Success etc
4.Again click on Advanced
5.Select Content type as html
6.Add your content for each trigger with HTML tags along with it
7.Also select ‘Do not attach Build Log’
You should be able to get it working. Let me know how it goes.
Regards,
VJ
LikeLike
Hi,
I have run out of options trying to configure extended email with attachments.
1. Configured the email trigger for all the scenarios.
2. Workspace for Jenkins &project are same.
3. Tried all possible paths for FILE,path
4. Configured extended email configurations for all the three Project configurations, Global configurations & email template.
I receive emails with logs only on build failures without attachments & email notification with only a Jenkins URL on build success.
I have urgent deliverables and need your help very very badly !!
LikeLike
Try using ${FILE,path=”E:/completepath/emailable-report.html”}. This worked for me. It sends html report in email body.
LikeLike
This post is a great help in setup – thank you! I can receive emails based on my trigger, and include the build.log. But I can not get my emailable-report.html to attach. Every email comes through with a line of text like:
${FILE,path=”CRM Service Tests\target\surefire-reports\emailable-report.html”}
I am running on Windows 10 as a Jenkins slave to a linux Jenkins server. On the windows slave, my full path is:
C:\Jenkins\workspace\CRM Service Tests\target\surefire-reports
I have tried different combinations of relative and absolute paths to the file, using forward and backslash, leading of each one. I have even tried a static file at C:/Jenkins/workspace/test.txt , C:\Jenkins\workspace\test.txt, and test.txt.
I still cant get the report or attachment. Any help would be greatly appreciated!!
LikeLike
Hey Jason,
Try this out :-
>Click on Triggers in Editable Email Notifications section
>You have a field named “Attachments”.
>Give the absolute/relative path of your file in that editbox.
I wish I could help you better by trying this out myself, but I’ve switched jobs so been away from implementing Jenkins stuff for a while. Though I’ll be back on it in a few weeks time 🙂
Let me know if this helps.
LikeLike
http://xyz.com:8080/view/DW_COD/job/COD_Sanity_Prod/ws/target/surefire-reports/emailable-report.html
This is my URL. If I need to trigger the mail for emailable report, what is the path I need to give. Pls suggest
LikeLike
Hey… I’m unsure if you can give a URL link for the report… I usually give the path relative to the physical location of the emailable report in the machine…
LikeLike
just enter below line in your attachment field
**/emailable-report.html
LikeLike
Hi,
It is working fine for me.
But my query is sometimes the html is not created
At that time, I am getting error message like file doesn’t exist
Is there any option to not throw an error in email body if the file is not available?
LikeLike
Hey Nivedithaa,
I’m not sure how we can do that… Do let me know if you can find out a solution for it. I’m unsure if we can include some sort of logic in the editable email notification plugin to handle such cases. But definitely worth a try.
LikeLike
Hi I get path content as body in my email.can you please help me
LikeLike
Or you need to just put below command in your attachments section in Editable Email Notification:
**/emailable-report.html
LikeLike
Hey I am using:
${FILE,path=”reports/emailable-report.html”}
I have set the content type as HTML(text/html)
But i am seeing the text “${FILE,path=”reports/emailable-report.html”}” in the email body.
However, when i use the path reports/emailable-report.html then i can see the report as an attachment.
TIA
LikeLike
Is it? I never knew that..Will try it out :)… Thanks for the input…
LikeLike
Ohhh…you mean you are able to send the report as an attachment, but not within the email body….
Can you delete the double quotes and re-insert them again…. Also there are no double quotes around the dollar sign…
LikeLike
Worked like a charm .
It would be great if you can edit the post saying workspace folder in relative path is not necessary
LikeLike
Alright will do…
LikeLike
I configured the project as u mentioned but once the test is completed I’m not able to send the mail I’m getting the following lines.
Email was triggered for: Always
Sending email for trigger: Always
Sending email to: email@email.in
Connection error sending email, retrying once more in 10 seconds…
Connection error sending email, retrying once more in 10 seconds…
Failed after second try sending email
Please help me to solve this issue.
LikeLike
Hey Durga,
I think you’ve not configured the SMTP server for jenkins.
To configure your SMTP server Go to Manage Jenkins >> Configure System.
Then in Email Notification section give in the SMPT server details of your organisation. Let me know if it works.
LikeLike
hi , i have a requirement to embed an jpeg image file in the email . i am able to add the image as attachment , but i would want to embed. I am using the editable email notification section. content type i have used html and also tried html and plain text. In the default content i have the following
The image is also present in a server path. It is also hosted on a webserver.I have also copied that image in the jenkins job workspace also.
But when i give the above code , only the first one works . This server location cannot be accessed outside office network. So i want the other two to work. Please help me find out why this does not seem to work.
LikeLike
I use cucumber extent and try to send it, but the mail doesn’t include html formatting and all the report without design,
How can i send a report with HTML page formatting?
Thanks
LikeLike
Hey Eitan,
You can custom make html reports if needed. Just read up on html basics, on how to make a table with different rows and columns. Use a language of your choice to create the html report.
LikeLike
Hi,
I am able to get html in my email body but after receiving the contents it is showing body as plain lines and all the html stylings are gone. Without styling it is looking very bad. Is there a way to resolve this?
If i want to write a script and parse a html for html body what do i have do?
LikeLike
Hi Kanheiya.. I am also having same issue. If your issue got resolved, please let me know ! Because i have received email body without Proper UI. Please help me!
LikeLike
Hey hi Vj,
I am able to get the emailable-report.html as attachment but when i set the pre-send-script: def reportPath = build.getWorkspace().child(“Portal/portalTests/test-output/surefire/**/emailable-report.html”)
msg.setContent(reportPath.readToString(), “text/html”);
i get an error in jenkins saying:
Caused by: java.io.FileNotFoundException: /Users/admin/jenkins/workspace/ScmPlanningAndBuyingUITests/Portal/portalTests/test-output/surefire/**/emailable-report.html (No such file or directory)
the actual path to the report is: Portal/portalTests/test-output/surefire/${timestamp}/emailable-report.html and i am using the wildcard since the groovy script cannot is not able to recognise ${timestamp}.
also i tried setting ${FILE,path=”Portal/portalTests/test-output/surefire/${timestamp}/emailable-report.html”} in the default content, but it prints the above statement in the email
any idea where am i going wrong?
LikeLike
Is there a way to send image file in contents and location is URL?
LikeLike
Can we have to write editable email report and placed into git url which we are using for building the plan
LikeLike
hi VJ,
please can you assist me
i have followed ur steps and successfully generated reports and recieved those reports to my outlook but the issue that i am facing is, the reports that i am receiving in outlook does not have CSS formatting (i.e graphs, colours are missing in the mail)
kindly can you advise me on the same. i am completely new to Jenkins and selenium
regards
Krishna
LikeLike
How to check file(reports/emailable-report.html) exist or not before running
${FILE,path=”reports/emailable-report.html”}.
In my case, some time report will not be generated . In this case i want to display some message.
LikeLike
I have done this…In jenkins it is showing “Sending email to: My mail address ” but I am not getting any mail.
LikeLike
Hi , can you please let me know how we can send HTML report at attachment in the email
LikeLike
${FILE,path=”E:/Jenkins/SERA_AutomationSuit/workspace/SpecFramework.SL.TestProject/bin/Debug
Job name: SERA_AutomationSuit
Project: SpecFramework.SL.TestProject
inside Debug folder all my .html files are generated everytime jenkins builds run
Now how to pass it dynamically after debug such that after every jenkins runs it picks up the file automatically
${FILE,path=”E:/Jenkins/SERA_AutomationSuit/workspace/SpecFramework.SL.TestProject/bin/Debug/?
what to pass in ?
My HTML file format looks like: SpecFramework.SL.TestProject_Default_2017-10-06T181730.html
where date time stamp changes every time
Please help?
LikeLike
Hi vj,
For adding test results in the email body, I followed your steps.
Since I’ve some other contents as well (apart from the relative path) in the default content, it’s just printing the path in the email body.
I want the email to display the content (such as: This is auto-generated email to publish test results. Please find the build report below) with the index.html. Is it possible?
LikeLike
Hey please help ASAP
My File path in Jenkins is job/testFreeStyle/ws/extentReportFile.html
I got this following error when I try to attach the file by this line
${FILE,path=”job/testFreeStyle/ws/extentReportFile.html”}
06:39:48 ERROR: Error accessing files to attach: Expecting Ant GLOB pattern, but saw ‘/var/lib/jenkins/workspace/testFreeStyle/extentReportFile.html’. See http://ant.apache.org/manual/Types/fileset.html for syntax
06:39:48 An attempt to send an e-mail to empty list of recipients, ignored.
06:39:48 Sending email for trigger: Always
06:39:48 ERROR: Error accessing files to attach: Expecting Ant GLOB pattern, but saw ‘/var/lib/jenkins/workspace/testFreeStyle/extentReportFile.html’. See http://ant.apache.org/manual/Types/fileset.html for syntax
06:39:48 ERROR: Error accessing files to attach: Expecting Ant GLOB pattern, but saw ‘/var/lib/jenkins/workspace/testFreeStyle/extentReportFile.html’. See http://ant.apache.org/manual/Types/fileset.html for syntax
06:39:48 Sending email to: ***@gmail.com
06:39:49 Finished: FAILURE
LikeLike
Hi Vj,
As per your blog, i have configured email, jenkins triggering email but i am not receiving emails,
Email was triggered for: Success
Sending email for trigger: Success
Sending email to: xxx@gmail.com
Finished: SUCCESS
LikeLike
Hi VJ,
As per your blog, I have configured all the settings in Advanced settings under Editable Email notification, In the console out put it is showing email successfully triggered but i am not receiving email How ever I am able to receive email through Email notification.
Can you help me asap.
Thanks
KK
LikeLike
Hi VJ,
I have configured all the steps as above. but when i get mail on build failure something like this it is shown:
See
——————————————
Started by user XXX
Building in workspace
No emails were triggered.
[Selenium1] $ cmd /c call C:\Users\Virima\AppData\Local\Temp\jenkins6816648486608600122.bat
run.bat>
java> -cp bin;lib\* org.testng.TestNG testng.xml
[TestNG] Running:
Please help me. I want TestNG Reports should be within the Jenkins Email Notifications
Thanks
Archana
LikeLike
hi i got following error in send mail
ERROR: Error accessing files to attach: Expecting Ant GLOB pattern, but saw ‘D:\workspace\command\test-output\emailable-report.html
LikeLike
Helpful article.. please update the post for below,
In point #4:
${FILE,path=”relative path to html file”}
Eg: ${FILE,path=”MyWorkspace/MyProj/test-output/emailable-report.html”}
above 2 lines should be,
${FILE,path=”relative path to html file”}
Eg: ${FILE,path=”MyWorkspace/MyProj/test-output/emailable-report.html”}
Double quote for the path value is the difference. When I copied it was not finding the file location, after several attempts.. I changed double quote… and it worked.
thanks
LikeLike
Hi, this method works for me! thanks! But in Outlook my report is not showing the screenshots whereas i am able to see in the report in jenkins. any ideas?
LikeLike
Hello,
this has been very helpful. I am trying to get index.html report with similar syntax. but in email it displays as plain text rather than html page. any feedback would be appreciated.
Regards,
Uma
LikeLike