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

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).

Related

JMeter & Jenkins - passing jmeter parameters to downstream build

The Setup - A jenkins job using jenkins parameters testApp and testEnv. The Execution Batch looks like this:
C:\jmeter\apache-jmeter-3.2\bin\jmeter.bat -n -t
C:\JMeter\Scripts\API_scripts\%testApp%.jmx -Jtestenv=%testEnv% -JtestApp=%testApp% -JtestBrowser=NA -l
C:\AUTO_Results\jtl\%testApp%_%testEnv%.jtl
Post-build Actions
Console output (build lob) parsing with a global rule so that the Failures that are logged in the Jenkins Console window will consider the JMeter script failing. (discussed Jenkins shows JMeter script failure even though the script actually passed)
Triggered parameterized build - this is a separate jmeter script that updates a wiki page with either PASS/FAIL and uploads the JMeter report.
The Issue - How do I get the downstream Triggered build to use the parameters from the upstream script? I set the Parameter = Current build parameters but it's not applying those. Also, I wont know the value of the testResult parameter until the upstream build finishes. I tried adding %testResult%=PASS to the 'Predefined parameters' box
As per Parameterized Trigger Plugin page:
The parameters section can contain a combination of one or more of the following:
a set of predefined properties
properties from a properties file read from the workspace of the triggering build
the parameters of the current build
Subversion revision: makes sure the triggered projects are built with the same revision(s) of the triggering build. You still have to make sure those projects are actually configured to checkout the right Subversion URLs.
Restrict matrix execution to a subset: allows you to specify the same combination filter expression as you use in the matrix project configuration and further restricts the subset of the downstream matrix builds to be run.
So you basically need to copy over the parameters you would like to have in the "downstream" job from the current one.
As a workaround to current performance plugin limitations you can consider running JMeter using Taurus tool as a wrapper, it has flexible and powerful pass/fail criteria subsystem which will basically return to Jenkins non-zero exit code triggering build failure in case of issue in the test. If everything goes well Taurus exit code will be 0 which is considered successful by Jenkins. Check out How to Run Taurus with the Jenkins Performance Plugin article for more details.

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

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.

Using Jenkins Job DSL plugin, why are the metrics (FindBugs, Checkstyle, PMD) only checked after the build?

Until recently, we created our Jenkins jobs by hand. We have a policy that the code is checked using FindBugs, Checkstyle and PMD, and any project that exceeds certain thresholds is considered unstable and is not allowed to deploy its artifact to our Maven repository.
In Jenkins, when I create a "Maven project", I get the metrics configuration under "Build Settings". If any threshold is exceeded, the build is considered unstable, and the Post-Build Action "Deploy artifacts to Maven repository" is not executed. This is how it should be.
However, in our generated jobs, which are generated using mavenJob(), the situation is different. Here, the metrics are added to the publisherContext, and thus if the threshold is exceeded, the build is still considered unstable, but nothing prevents the artifact to be deployed to the Maven repository.
Did I miss something? How can I add the metrics to the Build Settings as before?
You can use deployArtifacts{} with evenIfUnstable(false) to set this explicitly:
mavenJob('example-job') {
publishers {
deployArtifacts {
evenIfUnstable(false)
}
}
}

Resources