【问题标题】:sonar-scanner.bat fails with 401 on api/settings/values.protobuf when executed by jenkins pipeline由詹金斯管道执行时,声纳扫描仪.bat 在 api/settings/values.protobuf 上失败并显示 401
【发布时间】:2018-02-17 00:10:54
【问题描述】:

当我执行下面的管道时,http://mysonarhost.my.domain:9000/api/settings/values.protobuf 出现 401 错误。

在命令提示符下执行相同的命令不会出错。 可以使用浏览器访问 api/settings/values.protobuf URL。

我尝试在不同的地方设置令牌,但似乎没有任何帮助。

版本

  • sonarqube 版本 6.3.1(内部版本 21392)
  • 詹金斯版本。 2.75 在 RHEL 7 上
  • Windows 2012 R2 上的 Jenkins 节点
  • 声纳扫描仪 2.8

管道

https://i.imgur.com/S3Vk0fl.png

日志

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

【问题讨论】:

    标签: jenkins-pipeline sonarqube-scan


    【解决方案1】:

    感谢 Gilles QUERRET 的回答和 cmets,我设法解决了这个问题。

    • 令牌应该在 sonar.login 属性中
    • 添加了 withCredentials 节点
    • 将 ID 为 SONAR_TOKEN 的令牌存储在 http://myjenkinsserver:8090/credentials/store/system/domain/_/
    • 将 bat 命令中的单引号更改为双引号,以允许评估 $SONAR_TOKEN
    • 不是最初问题的一部分,添加了 -Dsonar.projectVersion=${env.BUILD_NUMBER} 以在 SonarQube 中显示 Jenkins 内部版本号

    工作阶段定义

    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}"
              }
          }
      }
    }
    

    【讨论】:

      【解决方案2】:

      documentation,属性应该是sonar.login,而不是sonar.logon

      【讨论】:

      • 附带说明,您的令牌不应在管道描述中以明文形式出现。您应该使用 withCredentials 节点(参见 jenkins.io/doc/pipeline/steps/credentials-binding )并将令牌存储在 Jenkins 中。
      • 这解决了我的问题,由于某种我不知道的原因,当我运行命令行时我的属性错误并不重要
      猜你喜欢
      • 2021-01-08
      • 2019-10-27
      • 1970-01-01
      • 2021-02-09
      • 2020-01-10
      • 2015-03-19
      • 2017-11-02
      • 2017-08-25
      • 1970-01-01
      相关资源
      最近更新 更多