8

I've read over the Jenkins site and its JUnit plugin, and for some reason something that is very basic is just not apparent to me.

Jenkins has an Email-ext plugin for sending custom/advanced notification emails whenever a build is ran. In these emails you can place "content tokens" that are runtime variables that get replaced with dynamic values when the email is being generated.

One of these tokens is TEST_COUNTS which allows you to display the number of JUnit tests that ran, or which failed, etc.

How does one go about getting Jenkins to display this information correctly? Is there a plugin I need, and if so, which one? I have my build running JUnit and generating an XML report. I assume Jenkins somehow parses JUnit results out of that XML and uses it to give values to that token.

But on the other hand, I've read "literature" (mailing list posts) that seems to suggest that in order to use that token you need to use Jenkins to run the unit tests, not a junit Ant task from inside your build script.

Can someone clarify this for me and perhaps even set out the "order of operations" for what steps I need to take in order to be able to make use of this token?

It would be supremely useful to get test counts in our build notifications.

nwinkler
  • 52,665
  • 21
  • 154
  • 168
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756

2 Answers2

14

Your first explanation is right. You tell Jenkins where to search for JUnit output files, and it parses them to find out the test results:

Screenshot of the Jenkins configuration

The test results appear on each project and build page, so as long as you're seeing the correct results there, you should get the correct token replacements in your e-mails

shahjapan
  • 13,637
  • 22
  • 74
  • 104
Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
  • Thanks Michael! One last item I need clarification on though. I have the `Email-ext` plugin configured but I don't see anything that looks like the screenshot from your response. This tells me that you took the screenshot from the JUnit plugin UI, yes? If so I'll have to install the JUnit plugin (if so, which one - there are lots!!!) , otherwise please tell me where to find those options (`Publish JUnit test result report`, etc.). Thanks again! – IAmYourFaja Jan 09 '12 at 15:18
  • 6
    That's under the "Post-build actions" -- it's there by default for Freestyle and Multi-configuration jobs, at least. No plugins required. – Christopher Orr Jan 09 '12 at 15:25
4

Add something like this to the content in the "Editable Email Notification" configuration:

Total = $TEST_COUNTS
Failed = ${TEST_COUNTS,var="fail"}

I also recommend the Jenkins users mailing list for Jenkins questions, usually helpful.

oeuftete
  • 2,628
  • 1
  • 24
  • 33
  • Thanks and yes I already have something like that. It's showing that "**No tests ran**" in the build notification, which isn't true (as is evidenced by the XML reports I can see in the build workspace!). This tell me I don't have Jenkins configured correctly to *parse* the XML information out of the JUnit reports. – IAmYourFaja Jan 09 '12 at 15:14