Jenkins Pipeline: How to fail on junit results

3,677 views
Skip to first unread message

Frank Hask

unread,
Apr 7, 2016, 8:17:21 AM4/7/16
to Jenkins Users
Hi all,

i am creating build pipeline and i am stuck at the integration tests stage.

This stage generates junit test results in XML format and if there are some failures pipeline just ignores it and continue as usual. But i want to stop pipeline and mark it as failure on test failure.

I have exhausted all possible ways so i am posting this topic in hope that someone has figured this out and wants to share it with community.

John Long

unread,
Apr 29, 2016, 6:44:03 PM4/29/16
to Jenkins Users
You can use the junit reporting plugin to do this. Once you've installed it, you can call it with code like this:
    step([$class: 'JUnitResultArchiver', keepLongStdio: true, testResults: 'target/test-reports/TEST*.xml'])

The snippet creator can help you when you select "step: General Build Step".

Craig Rodrigues

unread,
Apr 29, 2016, 9:48:43 PM4/29/16
to Jenkins Users, nikoli...@gmail.com
If you call JUnitArchiver from inside a pipeline, I think it
throws an exception if there is a test failure.
You need to catch the exception, explicitly set currentBuild.result to FAILURE,
and then re-throw the exception.

It took me a long time to figure it out. :)

--
Craig


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/7f0fde36-5c82-4fe4-8aa0-65e47f8aa379%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages