Including TestNG Reports within the Jenkins Email Notifications.

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

Advertisements

52 responses to “Including TestNG Reports within the Jenkins Email Notifications.

  1. 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.

    Like

      • 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”}

        Like

      • 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”}

        Like

      • 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.

        Like

  2. 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

    Like

    • 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…

      Like

  3. can u plz help out to send mail…

    Content Type HTML

    Default Subject

    Default Content ${FILE,path=D:\Jenkins\Jenkinsproject\JenkinsPracties\emailable-report.html”}

    Like

    • 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…

      Like

  4. 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

    Like

    • 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”}

      Like

  5. 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

    Like

  6. 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.

    Like

  7. 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.

    Like

    • 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

      Like

  8. 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 !!

    Like

  9. 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!!

    Like

    • 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.

      Like

  10. 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?

    Like

    • 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.

      Like

  11. Or you need to just put below command in your attachments section in Editable Email Notification:

    **/emailable-report.html

    Like

  12. 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

    Like

  13. 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.

    Like

    • 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.

      Like

  14. 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.

    Like

  15. 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

    Like

    • 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.

      Like

  16. 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?

    Like

  17. 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?

    Like

  18. 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

    Like

  19. 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.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s