Sonarqube analysis is getting failed in Jenkins pipeline

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube : Data Center EditionVersion 8.9.7 (build 52159), Scanner :sonar-scanner-4.6.2.2472, Plugin, and any relevant extension)
  • what are you trying to achieve : sonar analysis
  • what have you tried so far to achieve this : Tried executing locally, its working fine.

Error:

14:29:09  QUALITY TESTS ##################################################################
14:29:09  [Pipeline] dir
14:29:09  Running in /home/syspcbjenkins/store/workspace/_ecm_build_release_release-1.1.1
14:29:09  [Pipeline] {
14:29:09  [Pipeline] fileExists
14:29:09  [Pipeline] tool
14:29:09  [Pipeline] echo
14:29:09  Tool : /home/syspcbjenkins/store/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar-scanner-latest/sonar-scanner-4.6.2.2472
14:29:09  [Pipeline] echo
14:29:09  WORKSPACE : /home/syspcbjenkins/store/workspace/_ecm_build_release_release-1.1.1
14:29:09  [Pipeline] echo
14:29:09  SONARQUBE_URL : https://sonarqube02.barcapint.com
14:29:09  [Pipeline] echo
14:29:09  MYAPP_SONAR_PROJECT_KEY : BPI::BPI::DATASTREAMER_SVC::SNSVC0033409::BPI_DATASTR::DEVELOP
14:29:09  [Pipeline] echo
14:29:09  MYAPP_SONAR_PROJECT_NAME : BPI::BPI::DATASTREAMER_SVC::SNSVC0033409::BPI_DATASTR::DEVELOP
14:29:09  [Pipeline] echo
14:29:09  RELEASE_VERSION : 1.1.43-RELEASE
14:29:09  [Pipeline] echo
14:29:09  In createSonarProject
14:29:09  [Pipeline] withCredentials
14:29:09  Masking supported pattern matches of $SONAR_TOKEN
14:29:09  [Pipeline] {
14:29:09  [Pipeline] isUnix
14:29:09  [Pipeline] sh
14:29:10  + curl -k -u **** -X POST 'https://sonarqube02.barcapint.com/api/projects/create?project=BPI::BPI::DATASTREAMER_SVC::SNSVC0033409::BPI_DATASTR::DEVELOP&name=BPI::BPI::DATASTREAMER_SVC::SNSVC0033409::BPI_DATASTR::DEVELOP'
14:29:10  Enter host password for user ****:
14:29:10    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
14:29:10                                   Dload  Upload   Total   Spent    Left  Speed
14:29:10  
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   131  100   131    0     0    264      0 --:--:-- --:--:-- --:--:--   264
14:29:10  BUILD OUTPUT DIRECTORY : /home/syspcbjenkins/store/workspace/_ecm_build_release_release-1.1.1/target
14:29:10  [Pipeline] withCredentials
14:29:10  Masking supported pattern matches of $SONAR_TOKEN
14:29:10  [Pipeline] {
14:29:10  [Pipeline] echo
14:29:10  sonarCommand: /home/syspcbjenkins/store/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar-scanner-latest/sonar-scanner-4.6.2.2472/bin/sonar-scanner -X 
14:29:10  [Pipeline] isUnix
14:29:10  [Pipeline] sh
14:29:11  + /home/syspcbjenkins/store/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar-scanner-latest/sonar-scanner-4.6.2.2472/bin/sonar-scanner -X
14:29:11  09:59:10.873 INFO: Scanner configuration file: /home/syspcbjenkins/store/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar-scanner-latest/sonar-scanner-4.6.2.2472/conf/sonar-scanner.properties
14:29:11  09:59:10.879 INFO: Project root configuration file: /home/syspcbjenkins/store/workspace/_ecm_build_release_release-1.1.1/sonar-project.properties
14:29:11  09:59:10.900 INFO: SonarScanner 4.6.2.2472
14:29:11  09:59:10.900 INFO: Java 1.8.0_311 Oracle Corporation (64-bit)
14:29:11  09:59:10.900 INFO: Linux 3.10.0-1160.62.1.el7.x86_64 amd64
14:29:11  09:59:11.042 DEBUG: keyStore is : 
14:29:11  09:59:11.043 DEBUG: keyStore type is : jks
14:29:11  09:59:11.043 DEBUG: keyStore provider is : 
14:29:11  09:59:11.043 DEBUG: init keystore
14:29:11  09:59:11.043 DEBUG: init keymanager of type SunX509
14:29:11  09:59:11.178 DEBUG: Create: /home/syspcbjenkins/.sonar/cache
14:29:11  09:59:11.179 INFO: User cache: /home/syspcbjenkins/.sonar/cache
14:29:11  09:59:11.179 DEBUG: Create: /home/syspcbjenkins/.sonar/cache/_tmp
14:29:11  09:59:11.181 DEBUG: Extract sonar-scanner-api-batch in temp...
14:29:11  09:59:11.185 DEBUG: Get bootstrap index...
14:29:11  09:59:11.186 DEBUG: Download: http://localhost:9000/batch/index
14:29:11  09:59:11.215 ERROR: SonarQube server [http://localhost:9000] can not be reached
14:29:11  09:59:11.215 INFO: ------------------------------------------------------------------------
14:29:11  09:59:11.215 INFO: EXECUTION FAILURE
14:29:11  09:59:11.215 INFO: ------------------------------------------------------------------------
14:29:11  09:59:11.215 INFO: Total time: 0.361s
14:29:11  09:59:11.245 INFO: Final Memory: 7M/245M
14:29:11  09:59:11.245 INFO: ------------------------------------------------------------------------
14:29:11  09:59:11.245 ERROR: Error during SonarScanner execution
14:29:11  org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
14:29:11  	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
14:29:11  	at java.security.AccessController.doPrivileged(Native Method)
14:29:11  	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
14:29:11  	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
14:29:11  	at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
14:29:11  	at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
14:29:11  	at org.sonarsource.scanner.cli.Main.execute(Main.java:73)
14:29:11  	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
14:29:11  Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
14:29:11  	at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)
14:29:11  	at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
14:29:11  	at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
14:29:11  	at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
14:29:11  	... 7 more
===========================

Jenkins Sonar Stage

 stage("QUALITY TESTS") {
                    when {
                        // Only when enabled
                        expression { BUILD_ITEM.containsKey('sonar') && BUILD_ITEM.sonar.containsKey('enabled') && BUILD_ITEM.sonar.enabled }
                    }
                    steps {
                        script {
                            PipelineUtils.announceStage(this, 'QUALITY TESTS')

                            // Move into the build directory   
                            dir(BUILD_ITEM.rootDir) {

                                // The branch name is appended to the sonar project to create the full project key
                                // See: https://confluence.barcapint.com/display/IBATSonarQube/SonarQube+Naming+Conventions

                                // Need to replace any - or . with _
                                // branchName = env.BRANCH_NAME.replaceAll("[\\./-]", "_")
                                def sonarProjectKey = BUILD_ITEM.sonar.project // + "::${branchName}"
                                def existStatus = fileExists('./sonar-project.properties')
                                

                                QualityScanUtils.doJavaQualityScan(this, 
                                                    sonarProjectKey, 
                                                    sonarProjectKey, 
                                                    env.APP_VERSION, 
                                                    PIPELINE_SETTINGS.sonar.credentialsId, 
                                                    BUILD_ITEM.sonar.exclusions,
                                                    PIPELINE_SETTINGS.sonar.host,
                                                    PIPELINE_SETTINGS.sonar.toolVersion,
                                                    BUILD_ITEM.sonar.sources,
                                                    BUILD_ITEM.sonar.tests,
                                                    BUILD_ITEM.buildOutputDirectory,
                                                    existStatus               
                                                    )

Sonar Config file:

"sonar": {
        "host": "https://sonarqube02.barcapint.com",
        "credentialsId": "Token",
        "toolVersion": "sonar-scanner-latest"

Hey there.

It looks like in your organization, there are some custom libraries built to feed information to the scanner QualityScanUtils, and somehow the value for the sonar.host.url (PIPELINE_SETTINGS.sonar.host) isn’t actually getting passed to the scanner command, or it’s being overridden. You’ll need to look closer at the implementation of this library to understand how it works, and where it might be going wrong.