Jenkins plugin can't parse SonarQube url when using Gradle scanner

756 views
Skip to first unread message

Mark Gortzak

unread,
Aug 9, 2017, 3:03:51 AM8/9/17
to SonarQube
Hi all,

We are running Jenkins (2.60.1) with the SonarQube Scanner for Jenkins (2.6.1) on SonarQube 5.6.5. We use a scripted pipeline to build/test/analyze/publish. In the pipeline we use Gradle (3.4) with the SonarQube Gradle plugin (2.5) to analyze the code. Snippet of the Jenkinsfile:
stage('SonarQube analysis') {
withSonarQubeEnv('SONARQUBE') {
buildInfo.env.capture = false // verzamel hier niet de build info
gradle.deployer.deployArtifacts = false // artifacts moeten niet gedeployed worden
gradle.run(
rootDir: '',
buildFile: 'build.gradle',
tasks: 'sonarqube',
buildInfo: buildInfo,
switches: params.release ? '-Prelease' : '')
}
}

Snippet of the build.gradle:
sonarqube {
properties {
property "sonar.projectKey", "h3-java-framework-model-common"
property "sonar.projectName", "H3 - Java Framework model.common"
property "sonar.projectVersion", baseVersion
property "sonar.sourceEncoding", "windows-1252"
}
}

The analysis itself runs just fine. I can go to Sonarqube and see the project analysis being processed. I just can't click on the SonarQube link in the Jenkins job. Inspecting the HTML gives me this:
<div class="middle-align build-badge" style="width: 100%;">
  &nbsp;
    <img src="/plugin/artifactory/images/artifactory-icon.png" width="16" alt="[Artifactory]" title="Artifactory Build Info" height="16">
  </a>
  <a>
    <img src="/plugin/sonar/images/waves_16x16.png" width="16" alt="[sonarqube]" title="Analyzed by SonarQube" height="16">
  </a>
</div>
The link just isn't there!

I thought the problem was the Artifactory Gradle runtime (which I can't not use), but either using the runtime or not, the result is the same. No clickable SonarQube link. So I did some digging. I found this link; https://stackoverflow.com/questions/30934351/link-to-sonarqube-on-jenkins-job-not-available. Which gives me the following code from hudson.plugins.sonar.utils.SonarUtils:
/**
* Pattern for Sonar project URL in logs
*/
public static final String URL_PATTERN_IN_LOGS = ".*" + Pattern.quote("ANALYSIS SUCCESSFUL, you can browse ") + "(.*)";

/**
* Read logs of the build to find URL of the project dashboard in Sonar
*/
public static String extractSonarProjectURLFromLogs(Run<?, ?> build) throws IOException {
return extractPatternFromLogs(URL_PATTERN_IN_LOGS, build);
}
It seems to me that the Jenkins SonarQube plugin parses the log for the link. I supplied the "--info" switch to the Artifactory Gradle runtime. Et voila, a clickable link!

Here is a log snippet with the --info switch:
Loading findbugs plugin: D:\agent\workspace\java-base\h3-model-common\build\sonar\findbugs\fb-contrib.jar
Loading findbugs plugin: D:\agent\workspace\java-base\h3-model-common\build\sonar\findbugs\findsecbugs-plugin.jar
Findbugs output report: D:\agent\workspace\java-base\h3-model-common\build\sonar\findbugs-result.xml
The following classes needed for analysis were missing:
  javax.crypto.spec.SecretKeySpec
  javax.crypto.Mac
  org.jboss.logging.Logger
  org.slf4j.Logger
Sensor FindBugs Sensor (done) | time=27520ms
Sensor SurefireSensor
parsing D:\agent\workspace\java-base\h3-model-common\build\test-results\test
Sensor SurefireSensor (done) | time=157ms
Sensor JaCoCoSensor
Analysing D:\agent\workspace\java-base\h3-model-common\build\jacoco\test.exec
No information about coverage per test.
Sensor JaCoCoSensor (done) | time=458ms
Sensor JaCoCoItSensor
JaCoCoItSensor: JaCoCo IT report not found: D:\agent\workspace\java-base\h3-model-common\target\jacoco-it.exec
Sensor JaCoCoItSensor (done) | time=2ms
Sensor JaCoCoOverallSensor
Analysing D:\agent\workspace\java-base\h3-model-common\build\jacoco\test.exec
Analysing D:\agent\workspace\java-base\h3-model-common\build\sonar\jacoco-overall.exec
No information about coverage per test.
Sensor JaCoCoOverallSensor (done) | time=234ms
Sensor SonarJavaXmlFileSensor
Sensor SonarJavaXmlFileSensor (done) | time=1ms
Sensor Zero Coverage Sensor
Sensor Zero Coverage Sensor (done) | time=99ms
Sensor Code Colorizer Sensor
Sensor Code Colorizer Sensor (done) | time=10ms
Sensor CPD Block Indexer
JavaCpdBlockIndexer is used for java
Sensor CPD Block Indexer (done) | time=463ms
Calculating CPD for 156 files
CPD calculation finished
Analysis report generated in 1349ms, dir size=2 MB
Analysis reports compressed in 1500ms, zip size=1 MB
Analysis report uploaded in 192ms
Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
:sonarqube (Thread[main,5,main]) completed. Took 1 mins 5.488 secs.

And a log snippet without the --info switch:
[h3-model-common] $ cmd.exe /C "D:\appl\gradle-3.4\bin\gradle.bat --init-script C:/Users/AA_JEN~1/AppData/Local/Temp/init-artifactory8583628148362736073gradle sonarqube -b build.gradle && exit %%ERRORLEVEL%%"
:compileJava UP-TO-DATE
:processResources NO-SOURCE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:sonarqube
Classes not found during the analysis : [org.jboss.logging.Logger, org.slf4j.Logger]
The following classes needed for analysis were missing:
  javax.crypto.spec.SecretKeySpec
  javax.crypto.Mac
  org.jboss.logging.Logger
  org.slf4j.Logger

BUILD SUCCESSFUL

Total time: 1 mins 11.196 secs

So, concluding, I think there is a bug. Using the SonarQube Gradle plugin following the manual (https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle) doesn't yield a clickable link in Jenkins. I see a few solutions:
1. Adding the --info switch and take for granted a more verbose log
2. Changing the way the URL resolving works. The URL can be resolved from the base url (in <user>/.gradle/gradle.properties) and the project key in the build.gradle.
3. Changing the Gradle SonarQube plugin so that it always outputs the necessary text.

Thanks for reading and for your help.

With regards,
Mark Gortzak


Julien HENRY

unread,
Aug 9, 2017, 3:58:32 AM8/9/17
to SonarQube
Hi Mark,

We already have a ticket for this problem:

You can follow progress there.

++

Julien

Mark Gortzak

unread,
Aug 9, 2017, 5:54:34 AM8/9/17
to Julien HENRY, SonarQube
Hi Julien,

Thanks for the reply. I'll keep an eye out for version 2.7 :-).

Greetings,
Mark

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/Y8hQMLtPMSQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/93244679-fef9-414e-9d9c-df022f190287%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages