sonarqube project failed - jenkins

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

Related

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.

Jenkins sonar quality gates issue

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.

Jenkins - Build Status

I've created one Jenkins job to execution 5 test cases and it works, but not in terms of build creation.
Build status is coming as SUCCESS even if there is any failure test
cases during execution.
For instance, 2 test cases out of 5 got failed during my recent run, but the build status has become SUCCESS!!!
Please help me in correcting this.....
Note: I'm using Jenkins 1.617 & ANT 1.9.4 for the integration.
If you are executing junits in jenkins, default status is unstable for jenkins job and success for maven/ant build.
If you are using an ant build add the below property to junit task to make the build failed failureproperty="test.failed". If you want to fail the build even if one junit fails, add property haltonfailure="yes"
If you are using maven add the argument -Dmaven.test.failure.ignore=false

Link to SonarQube on Jenkins job not available

on the main page of a Jenkins job, I see the SonarQube icon, which should be a link, but it's just text:
I use...
Jenkins 1.596.2 (also tried 1.609.1)
Jenkins SonarQube-Plugin 2.1 (also tried 2.2.1)
Maven 3.3.1
sonar-maven-plugin:2.6 (when configuring SonarQube post build action)
sonar runner 2.4 (when configuring SonarQube analysis build step)
After browsing the source code of the jenkins sonarqube-plugin, I found that SonarUtils.extractSonarProjectURLFromLogs() seems to be broken. It parses the console output for the regexp "ANALYSIS SUCCESSFUL, you can browse (.*)".
My console output never prints this line. It just prints "ANALYSIS SUCCESSFUL".
Is this a known issue?
From what I can see in your logs, you are running the analysis in "preview" mode:
... -Dsonar.analysis.mode=preview ...
As you can read on the documentation about preview mode:
The source code is analyzed but the measures and issues are not pushed
to the SonarQube database. Therefore, they cannot be browsed through
the web interface.
So this is normal that you only get a ANALYSIS SUCCESSFUL message without the related SQ URL (because results are not pushed to the server in preview mode).

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