Jenkins sonar quality gates issue - jenkins

I have a Jenkins jobs for sonar analysis. When I try to add build step for Quality Gates (in order to mark a failure if new bugs), I get this error:
JSONObject["projectKey"] not found.
Can someone help?

Quality gates build step can only come under POST build actions.
So try to add post build action of Quality Gates. And make sure you are giving a project key.
Project Key can be taken note of from sonar server console.
This should solve the error.

Related

Sonar-Gerrit integration shows error in Jenkins

There is a Jenkins freestyle job that is triggered by some Gerrit events.In response to triggers, it downloads the changes and runs a Sonarqube Analysis. The Sonarqube comments detailing the results are to be posted on Gerrit after the analysis is complete.This is the expected behaviour.
As of now, In Jenkins, the Sonarqube execution is success. But the build is failed mentioning the error " *ERROR: Build step failed with exception java.lang.IllegalArgumentException: Gerrit change number is empty*
Could anyone please help on this?
Reference:https://plugins.jenkins.io/sonar-gerrit/
Followed the same steps as mentioned in the above document.
Jenkins console output
Expected: The Sonarqube should post the comments to the respective Gerrit change,whether the Sonar-verified is +1/-1.

Ignore failure of post build step in Jenkins

I have Jenkins job with summary plugin step in post build actions. Sometimes it fails because of absence of the necessary file for it(for some branches, and there is no ability to update them nearest time). Is it possible to ignore failure only in post build steps and mark build green?
Finally I found solution - in build steps add shell step with command "touch summaryName.xml". If file exists it won't be changed. And if there is no summary file it will be created
Yes, you can ignore the failure by ticking the check box [Do not fail this build if archiving returns nothing] in advanced section.

How can I force update code coverage trend graphs on failed jobs

How can I publish the results of the code coverage to the trend graph even if the job fails after the jacoco analysis?
For Findbugs, PMD, etc. this can be achieved with the canRunOnFailed setting. Is there something similar for JaCoCo?
On project level I see the trend graph which only considers the successful builds. I would also like to see the coverage graph updated if the job fails.
This is tracked by JENKINS-28479:
ProjectActions (and trend graphs) do not appear for failed projects
This problem is not only related to the JUnit plug-in. In general, every plug-in that has been migrated its actions to a SimpleBuildStep has this problem. The affected source code is in SimpleBuildStep.
A test case that exposes this bug is WarningsPluginTest#should_not_skip_failed_builds_with_option_run_always
This is still open.
Original answer:
This is not specific to the maven jacoco build step: all you need to do is make sure that build step always return "success".
If you are using pipelines, you can wrap your step in a try/catch.
If you are using a regular job definition, you could consider a shell/windows command step where you return 0 (or exit /b 0) after the mvn command.
The next build step would be the mvn sonar:sonar publication one, which will then always be executed.

sonarqube project failed

I am using sonarqube 6.1 which is integrated with Jenkins 2.48. In Jenkins, it is showing my build ran successfully. But in Sonarqube, it is showing Failed.
Jenkins :
POST BUILD TASK : SUCCESS
END OF POST BUILD TASK : 0
Finished: SUCCESS
Sonarqube (Failed in red color) :
[![enter image description here][1]][1]
What "failed" mean in Sonarqube project?
Does it means wrong configuration or wrong iteration with Jenkins?
How can I solve this?
I have checked in background task. Project failed recently but in project summery, it is showing past failed details.
[![enter image description here][2]][2]
The SonarQube analysis is split into two separate tasks:
The 'Sonar Scanner' runs the analysis on the code (which is what happens in your Jenkins build) and packs the results and sends them of to the SonarQube instance.
The 'Compute Engine' (CE) uses the packed results and calculates several quality metrics (for ex. the CE is responsible to update the Quality Gate status)
As your Jenkins build is successful this means that the Scanner did do it's work just fine, but on the CE side it failed to process the results of the scanner.
See Background Tasks documentation on how to obtain the log of the CE task and see why the analysis results processing failed.
The default configuration for SonarQube way flags the code as failed if:
the coverage on new code is less than 80%
percentage of duplicated lines on new code is greater than 3
maintainability, reliability or security rating is worse than A

Setting thresholds values - Java - Static Code analysis - SonarQube Sonar

So we have Checkstyle, PMD, Findbugs as tools which performs static code analysis or work on bytecode to find various issues in code and using them in Jenkins/Hudson (under Post build actions), can turn a build to a unstable, failed, successful build depending upon what threshold values we set there.
As SonarQube is the upcoming/future single dash for showing all such analysis in one page for a project/module, I was wondering where in SonarQube settings (I can set such threasholds) to make a build as a failed, unstable, successful i.e. Jenkins will launch the build (ANT/Maven/Gradle etc), calls, sonarRunner (task in Gradle) / sonar-runner (executable in Linux/Unix), then if threasholds are not good, then Jenkins will mark the build as unstable/failed/successful depending upon the set threashold values.
Any ideas?
See alerts / Quality Gates section in SonarQube.(http://docs.codehaus.org/display/SONAR/Quality+Profiles#QualityProfiles-alertsEditingAlerts) and Build Breaker plugin (http://docs.codehaus.org/display/SONAR/Build+Breaker+Plugin).

Resources