0

I'm running a Jenkins Pipeline where a build is triggered when a merge request is submitted. The build runs and SonarQube analyses the workspace. Another merge requested is submitted simultaneously and the build runs, but SonarQube fails with the following error:

ERROR: Error during SonarQube Scanner execution ERROR: Another SonarQube analysis is already in progress for this project

How to run multiple SonarQube analyses for the same project at the same time?

Souvik Dey
  • 653
  • 1
  • 9
  • 18
  • Would you be okay with having multiple workspaces for this pipeline? I.e do you keep things in between jobs runs or can you start from scratch every time? – Yazeed Sabri Dec 28 '18 at 19:22
  • I can start from scratch anytime. Does that mean that I need a different workspace altogether? Won't that consume disk space? – Souvik Dey Dec 29 '18 at 03:15
  • During a scan a project is "locked" see [here](https://github.com/SonarSource/sonarqube/blob/master/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectLock.java) – Jeroen Heier Dec 29 '18 at 14:57
  • @JeroenHeier So is there an alternative solution to this problem? I need to run SonarQube analyses for the same project at the same time. – Souvik Dey Dec 29 '18 at 15:17

1 Answers1

0

From Jenkins side, the solution is to have different repo dirs in your workspace for each checkout, that way you won't run into the same locked project twice. You can do this in multiple ways, it just depends on how many concurrent builds do you expect at the same time.

Assuming you're using Git, you can add this in the extensions section in your checkout command to have each build checked out in its own directory, based on its build number, and under one workspace directory (ie. your pipeline directory).

[$class: 'RelativeTargetDirectory', relativeTargetDir: "${BUILD_NUMBER}" ]

You have two choices to clean up, either use the "Wipe out repository & force clone" from the checkout command or the Workspace Cleanup Plugin.

Keep in mind that the checkout wipe command will delete everything under the directory you are about to do your next checkout in, meaning it will keep the rest of you workspace intact and won't work if you used the build number like the example above. Here is what you need to add to your extensions section:

[$class: 'WipeWorkspace']

The cleanWS plugin gives you greater flexibility since you are able to specify patterns for what you want to include, or exclude if you change the type:

cleanWs(patterns: [[pattern: '', type: 'INCLUDE']])

I hope this helps.

Yazeed Sabri
  • 346
  • 3
  • 17