Alternative to sonar build breaker plugin - break the jenkins job if sonar Quality gate fails

0

I want to break my jenkins job build whenever the sonar quality gate fails. I dont want to use the sonar build breaker plugin, and I know there is an alternative to that via jenkins pipelines, but we are not using pipelines, we want to go for freestyle jenkins jobs.

So I have narrowed it down to a couple of approaches

  1. use property sonar.qualitygate=True → only works for sonar 8.1 and up and we cannot upgrade as some plugins are not compatible
  2. write a script that does almost the same thing as the build breaker plugin Call the /api/ce/task?id=${ceTaskId} web service to retrieve analysisId. You can get the ceTaskId from /report-task.txt under your working directory. If the CE Task Status is PENDING or IN_PROGRESS, the script should wait, and repeat step 1 If the CE Task Status is SUCCESS, we save the analysisId and proceed to step 5 If the CE Task Status is FAILED or CANCELED, we break the build Call the /api/qualitygates/project_status?analysisId=${analysisId} web service to check the status of the quality gate If the quality gate status is OK or WARN, allow the build to pass. If the quality gate status is ERROR, we break the build.

The 4th approach works, but i want to know what happens when there are parallel sonar runs, like 2 or 3 developers are running the sonar scan and uploading at the same time, I think this approach might not work in that case.

Has anyone done any thing similar before, and can provide some pointers that can help

Hey there.

All that we (SonarSource) can recommend is to upgrade.

Out of curiosity – which ones are blocking the upgrade (which ones aren’t compatible?)

Hi Colin,
We are using fortify plugin for sonarqube that is not compatible with sonar 8 and up.

is there any way to achieve what I want, but not without upgrading sonar