Test description set from a Groovy Postbuild script disappears

464 views
Skip to first unread message

Eduard Moraru

unread,
Jan 6, 2015, 5:47:20 PM1/6/15
to jenkins...@googlegroups.com
Hi,

I have recently written a pretty nice along the lines of this blogpost http://brknthmb.com/post/76243353208/jenkins-adding-selenium-screenshots-to-test (with some modifications).

It is working great... however only for about 1 hour. After that, any descriptions set by the postbuild script (e.g. someCaseResult.description = "Some Description") on a failed test vanish like they were never there. When I come back later I only see the option "Add description" instead of the previously set description.

There is even an example in the plugin's documentation ( https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin#GroovyPostbuildPlugin-Example9%28thankstoKenBertelson%29 ) about doing it this way and I wonder if anyone else has encountered this problem and how I may get around it.

I am now trying to see if this replicates with a description that I set manually on a failed test result, I will come back tomorrow with the results of this test.

Using Jenkins ver. 1.565.3 LTS.

Thanks,
Eduard

Daniel Beck

unread,
Jan 6, 2015, 6:17:36 PM1/6/15
to jenkins...@googlegroups.com
Test results are stored in weak references to be discarded in case memory is required for something else. Builds themselves aren't kept in memory either. And the code you have does not persist test results to disk.

https://github.com/jenkinsci/junit-plugin/blob/master/src/main/java/hudson/tasks/junit/TestResultAction.java#L123...L142

Something like the following should work (untested):

def result = manager.build.testResultAction.result
failedTests = result.getFailedTests()
// changes to tests in the result here
manager.build.testResultAction.setResult(result, manager.listener)

You can check whether it works by looking at the junitResult.xml file's modification date and contents and/or restarting Jenkins.
> --
> 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/CADGDyYJvfjduApWJUZA2z-omksMbTX8sTHiJM_7kex9K2buWbQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Eduard Moraru

unread,
Jan 7, 2015, 6:31:21 AM1/7/15
to jenkins...@googlegroups.com
Hi,

It seems to make sense what you are saying, however, I can not get to an instance of TestResultAction.

I have tried many things and did a lot of printing to see what I am working with. Here is what I get for the following:

manager.build.getClass() --> class hudson.maven.MavenModuleSetBuild
manager.build.testResultAction.getClass() --> class hudson.maven.reporters.SurefireAggregatedReport
manager.build.aggregatedTestResultAction.getClass() --> class hudson.maven.reporters.SurefireAggregatedReport
manager.build.getAction(hudson.tasks.junit.TestResultAction.class) --> null
manager.build.getAction(hudson.tasks.test.AbstractTestResultAction.class) --> hudson.maven.reporters.SurefireAggregatedReport@bb1453
manager.build.testResultAction.result.getClass() --> class hudson.tasks.test.AggregatedTestResultAction$1 (assuming this one is ChildReport)
manager.build.testResultAction.getResult().getClass() --> class hudson.tasks.test.AggregatedTestResultAction$1 (assuming this one is ChildReport)

I`m a bit stuck at this point. Any idea?

Thanks,
Eduard

Eduard Moraru

unread,
Jan 7, 2015, 11:25:02 AM1/7/15
to jenkins...@googlegroups.com
So it seems that TestObjects are not persisted so I would have to use that protected method instead. AFAIK that works in Groovy, even if the method is persisted, so I tried the following, going from bottom-up this time:

testResultAction = failedTest.getParentAction()
testResult = testResultAction.getResult()

testResultAction.setDescription(failedTest, "Some description");
manager.build.save();

However, no luck!

For some reason, even if the setDescription menthod is supposed to set the description in the list of descriptions of the SurefireReport action (subclass of TestResultAction), the save method is not persisting the description in the build.xml file.

From setting the description manually, I can confirm that that is the place where it is supposed to be saved and that the SurefireReport action is the right one to use. Maybe I am not calling save() on the right instance?

I would really appreciate some help on this one since I am so close to finishing it and I have spent a lot of time going back and forward with it.

This is the full code of the progress I`ve done with my script. Just need to save the failed test's description...

Thanks,
Eduard

P.S.: I have stopped pursuing the setResults() method since I am almost sure that even if it saves stuff, it saves it to junitResult.xml and that does not hold descriptions. Again, from manual testing, it seems that build.xml stores the test descriptions inside the SurefireReport action.

Eduard Moraru

unread,
Jan 7, 2015, 11:25:56 AM1/7/15
to jenkins...@googlegroups.com
The full code progress I mentioned is here: http://hastebin.com/paruraheze.xml

Thanks,
Eduard

Eduard Moraru

unread,
Jan 8, 2015, 6:31:56 AM1/8/15
to jenkins...@googlegroups.com
I finally did it by using these 2 lines for setting and saving (to build.xml) the failed test's description:

      testResultAction.setDescription(failedTest, description);
      testResultAction.owner.save();

Thank you very much for your initial help, Daniel! It certainly sent me in the right general direction.

Hope this helps others having the same problem.

Thanks,
Eduard
Reply all
Reply to author
Forward
0 new messages