Jenkins and JUnit

2019-03-27 12:03发布

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.

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-03-27 12:23

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

查看更多
forever°为你锁心
3楼-- · 2019-03-27 12:34

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.

查看更多
登录 后发表回答