What am I using?
- SonarQube version: 8.9 Community edition installed as a docker container in a google cloud VM with an internal domain like https://sonarqube.internaldomain.com
- Using the sonarqube-gradle-plugin 3.3 version as part of Android codebase.
- JDK 11 on the Jenkins slave to perform the sonar scan and compilation of android codebase
What am I trying to achieve
I am trying to setup a nightly Jenkins job that will clone master branch of Android project, compile, run unit tests and run sonar scanner.
What does my configuration look like
gradle.properties file
# Sonarqube
systemProp.sonar.host.url=
systemProp.sonar.projectKey=Project-Key
systemProp.sonar.login=
build.gradle file
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3"
}
apply plugin: "org.sonarqube"
sonarqube {
properties {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.kotlin.detekt.reportPaths", "$buildDir/reports/detekt.xml"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.jacoco.reportPath", "$buildDir/reports/jacoco/jacocoTestInternalDebugUnitTestReport/jacoco.xml"
}
}
subprojects {
sonarqube {
properties {
property "sonar.sources", "**/src/main/java"
property "sonar.exclusions", "*.json,**/src/test/**/*,**/.gradle/**,**/R.class,*.proto"
property "sonar.tests","**/src/test/java"
property "sonar.coverage.exclusions","**/src/test/**/*,**/src/androidTest/**/*,test_common/**/*"
}
}
}
Jenkins job configuration
environment {
SONARQUBE_LOGIN_TOKEN = read from credentials
}
stages {
stage("Clean Workspace") {
steps {
cleanWs()
}
}
stage("Checkout Android project") {
steps {
//perform checkout with git scm
}
}
stage("Set properties") {
steps {
sh '''
setProperty(){
awk -v pat="^$1=" -v value="$1=$2" '{ if ($0 ~ pat) print value; else print $0; }' $3 > $3.tmp
mv $3.tmp $3
}
setProperty "systemProp.sonar.host.url" "${SONAR_URL}" gradle.properties
setProperty "systemProp.sonar.login" "${SONARQUBE_LOGIN_TOKEN}" gradle.properties
//This sets sonar properties in gradle.properties when the job runs.
//The values are passed via a Jenkins parameter and a jenkins credential.
'''
}
}
stage("Run unit tests") {
steps {
sh """
./gradlew testInternalDebugUnitTest
"""
}
}
stage("Run detekt") {
steps {
sh """
./gradlew detektAll
"""
}
}
stage("Run sonar scan") {
steps {
sh """
./gradlew sonarqube
"""
}
}
}
}
What is the error?
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':sonarqube'.
> Unable to execute SonarScanner analysis
* Try:
> Run with --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':sonarqube'.
...
Caused by: org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
...
Caused by: java.lang.IllegalStateException: Fail to parse entry in bootstrap index: <!DOCTYPE html>
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.parse(BootstrapIndexDownloader.java:59)
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:44)
at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
... 124 more
How do I fix this?
- I already checked some related queries on this community.
- I confirmed if it was a URL issue but the URL is correct.
- I also checked if the
/batch/index/
page returns some valid JAR information and it does
- There are some simple java+maven based projects in the same Jenkins environment where sonar analysis works perfectly fine via sonar maven plugin.