5

When I execute the pipeline below I get a 401 error on http://mysonarhost.my.domain:9000/api/settings/values.protobuf.

The same command executes without errors from a command prompt. The api/settings/values.protobuf URL can be accessed using a browser.

I tried setting the token in various places but none seem to help .

Versions

  • sonarqube Version 6.3.1 (build 21392)
  • Jenkins ver. 2.75 on RHEL 7
  • Jenkins Node on windows 2012 R2
  • sonar-scanner 2.8

pipeline

screenshot of pipeline scripthttps://i.stack.imgur.com/4bYiD.png

log

sonar-scanner -X -Dproject.settings=..\sonar_ccesmarttools.properties -Dsonar.logon=mytoken 
06:32:33.829 INFO: Scanner configuration file: X:\workspaces\common\tools\hudson.plugins.sonar.SonarRunnerInstallation\SonarQubeScanner\bin\..\conf\sonar-scanner.properties
06:32:33.836 INFO: Project root configuration file: X:\cce\SmartLisaNightly\git\ccesmarttools\CceSmartTools\..\sonar_ccesmarttools.properties
06:32:33.873 INFO: SonarQube Scanner 3.0.3.778
06:32:33.874 INFO: Java 1.8.0_73 Oracle Corporation (64-bit)
06:32:33.874 INFO: Windows Server 2012 R2 6.3 amd64
06:32:33.874 INFO: SONAR_SCANNER_OPTS=-Xmx16g
06:32:34.041 DEBUG: keyStore is : 
06:32:34.042 DEBUG: keyStore type is : jks
06:32:34.042 DEBUG: keyStore provider is : 
06:32:34.042 DEBUG: init keystore
06:32:34.042 DEBUG: init keymanager of type SunX509
06:32:34.158 INFO: User cache: C:\Users\jenkinsuser\.sonar\cache
06:32:34.158 DEBUG: Extract sonar-scanner-api-batch in temp...
06:32:34.173 DEBUG: Get bootstrap index...
06:32:34.173 DEBUG: Download: http://mysonarhost.my.domain:9000/batch/index
06:32:34.232 DEBUG: Get bootstrap completed
06:32:34.233 DEBUG: Create isolated classloader...
06:32:34.243 DEBUG: Start temp cleaning...
06:32:34.255 DEBUG: Temp cleaning done
06:32:34.255 DEBUG: Execution getVersion
06:32:34.260 DEBUG: Execution start
06:32:34.557 DEBUG: Publish global mode
06:32:34.698 INFO: Load global settings
06:32:34.749 DEBUG: GET 401 http://mysonarhost.my.domain:9000/api/settings/values.protobuf | time=43ms
06:32:34.751 INFO: ------------------------------------------------------------------------
06:32:34.751 INFO: EXECUTION FAILURE
06:32:34.751 INFO: ------------------------------------------------------------------------
06:32:34.751 INFO: Total time: 0.961s
06:32:34.788 INFO: Final Memory: 17M/1963M
06:32:34.788 INFO: ------------------------------------------------------------------------
06:32:34.788 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.bootstrap.ScannerPluginInstaller
carl verbiest
  • 1,113
  • 1
  • 15
  • 30

2 Answers2

3

From the documentation, the property should be sonar.login, not sonar.logon.

Gilles QUERRET
  • 563
  • 2
  • 5
  • 19
  • 1
    And as a side note, your token shouldn't be in clear text in your pipeline description. You should use the `withCredentials` node (see https://jenkins.io/doc/pipeline/steps/credentials-binding/ ) and store the token in Jenkins. – Gilles QUERRET Sep 08 '17 at 07:56
  • This solved my problem, for some reason unknown to me it did not matter that I had the wrong property when I ran for a command line – carl verbiest Sep 09 '17 at 06:21
1

I managed to solve it thanks to Gilles QUERRET answer and comments.

  • the token should be in the sonar.login property
  • added the withCredentials node
  • stored the token with id SONAR_TOKEN in http://myjenkinsserver:8090/credentials/store/system/domain/_/
  • changed single quotes in the bat command to double quotes to allow $SONAR_TOKEN to be evaluated
  • not part of the initial question, added -Dsonar.projectVersion=${env.BUILD_NUMBER} to show the Jenkins build number in SonarQube

Working stage definition

stage('SonarQube analysis') {
  withSonarQubeEnv('SonarQube') {
      withCredentials([string(credentialsId: 'SONAR_TOKEN', variable: 'SONAR_TOKEN')]) {
          def scannerHome = tool 'SonarQubeScanner';
          env.PATH = "${scannerHome}\\bin;${env.PATH}";
          dir('X:\\cce\\SmartLisaNightly\\git\\smartlisa\\SmartLisaFrontend') {
              bat "sonar-scanner -Dsonar.login=$SONAR_TOKEN -Dproject.settings=..\\sonar_SmartLisaFrontend.properties -Dsonar.projectVersion=${env.BUILD_NUMBER}"
          }
      }
  }
}
carl verbiest
  • 1,113
  • 1
  • 15
  • 30