Get failing tests related to a maven build in a pipeline script?

253 views
Skip to first unread message

Vincent Massol

unread,
Jan 30, 2018, 11:05:46 AM1/30/18
to Jenkins Users
Hi guys,

I know how to get the failing tests for a job with:

AbstractTestResultAction testResultAction = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
def failedTests = testResultAction.getResult().getFailedTests()

However, my pipeline job is executing Maven several times. 

Is there a simple way to do this or do I need to save the failing tests in a variable after each maven execution to compute the new failing tests?

Thanks
-Vincent


Victor Martinez

unread,
Jan 30, 2018, 12:08:13 PM1/30/18
to Jenkins Users
What about this: https://groups.google.com/d/msg/jenkinsci-dev/hI3aSyayYxQ/txGte6HQAAAJ ? Not sure whether the failureDiffString method might help you in this case.

Cheers

Vincent Massol

unread,
Jan 30, 2018, 12:15:20 PM1/30/18
to Jenkins Users
Thanks Victor. Not sure how failureDiffString would help. The issue is that this returns the failures from all past maven executions and not just for the last run.

FTM I've done this but it's overly complex and it would be nice to be able to get the failed tests related only to the last maven execution:

Note that I have to go through a global env variable to save the previous state and compare.

Thanks
-Vincent

Vincent Massol

unread,
Jan 31, 2018, 1:19:39 AM1/31/18
to Jenkins Users
Actually my code won't work. Just realized that 'env' can only store Strings. Thus I need a way to have some global variable shared between calls to my scripted pipeline library... Any idea?

Vincent Massol

unread,
Jan 31, 2018, 5:54:24 AM1/31/18
to Jenkins Users
And the solution is simpler, I just need to save the failing tests before the maven execution and compare with the full list of failing tests I get after that maven execution:

Thanks
-Vincent

Vincent Massol

unread,
Feb 1, 2018, 4:19:10 AM2/1/18
to Jenkins Users
Well, it doesn't work...

The issue is because we use parallel() step and thus we have several maven runs starting in parallel. So they start with empty failing tests but one of them can contribute failing tests to the others since all failing tests are accruing in currentBuild... :(

So I really need to find a way to identify how to get the failing tests for a given maven run...

Is there anything in CaseResult/TestResult would allow me to do this for example?

Any idea?

thanks
-Vincent
Reply all
Reply to author
Forward
0 new messages