I have a project that I’ve added to my Jenkins server. The project includes a parent and child maven pom file. I added builds for both the parent and the child pom files and everything worked correctly for a short while, but then the child build stopped working.
Whenever the child would get to the sonar analysis, I would get an exception like this:
Caused by: javax.persistence.NonUniqueResultException: Expected single result, but got : [Snapshot[resourceId=1148,createdAt=2011-04-29 23:08:23.0,version=01.01.01.1054-SNAPSHOT,last=true,status=P,scope=PRJ,path=,depth=0,qualifier=TRK,rootId=<null>,parentId=<null>,rootProjectId=1148,period1Mode=previous_analysis,period2Mode=days,period3Mode=days,period4Mode=<null>,period5Mode=<null>,period1Param=2011-04-19,period2Param=5,period3Param=30,period4Param=<null>,period5Param=<null>,period1Date=2011-04-19 05:06:16.0,period2Date=2011-04-24 23:08:23.0,period3Date=2011-03-30 23:08:23.0,period4Date=<null>,period5Date=<null>,id=486870], Snapshot[resourceId=1148,createdAt=2011-05-04 09:52:04.0,version=01.01.01.1054-SNAPSHOT,last=true,status=P,scope=PRJ,path=495746.,depth=1,qualifier=BRC,rootId=495746,parentId=495746,rootProjectId=1149,period1Mode=previous_analysis,period2Mode=days,period3Mode=days,period4Mode=<null>,period5Mode=<null>,period1Param=2011-04-29,period2Param=5,period3Param=30,period4Param=<null>,period5Param=<null>,period1Date=2011-04-29 23:08:23.0,period2Date=2011-04-29 09:52:04.0,period3Date=2011-04-04 09:52:04.0,period4Date=<null>,period5Date=<null>,id=495748]]
I’ve tried deleting and recreating the projects to no avail. Any solutions?
This is a bug in Sonar version < 2.8. You can look at the bug report here: Sonar-2329. Essentially the problem occurs when the parent and child builds are analysed by sonar simultaneously. To solve it you should do two things:
1) Remove either the parent or the child build from Jenkins. There should only be one project to build on Jenkins.
2) You will need to clean up the corruption in your database caused by the concurrent analysis. You can do this by running the following SQL command on your sonar database:
See the bug report for more details, as well as the SQL commands for other SQL dialects. The above query works for MySQL.