Travis 上的 SonarCloud 错误:未授权。请检查属性 sonar.login 和 sonar.password

SonarCloud error on Travis: Not authorized. Please check the properties sonar.login and sonar.password

我也在 Whosebug 上搜索了很多关于这个问题的信息,但没有找到解决方案。

直到昨天 Travis 都可以毫无问题地执行 sonar:sonar,但今天它不起作用,它给我这个错误:

--- sonar-maven-plugin:3.7.0.1746:sonar (default-cli) @ progetto ---

    [INFO] User cache: /home/travis/.sonar/cache
    [INFO] SonarQube version: 8.0.0
    [INFO] Default locale: "en_US", source code encoding: "UTF-8"
    [INFO] Load global settings
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  04:38 min
    [INFO] Finished at: 2019-11-08T15:56:40Z
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project progetto: Not authorized. Please check the properties sonar.login and sonar.password. -> [Help 1]

所以我改变了我的 SONAR_TOKEN 创建一个新的。但是什么都没有改变。 这是我的 Travis 文件:

language: java

jdk: openjdk8

env: DISPLAY=:99.0

services:
   - docker
   - xvfb
addons:
  sonarcloud:
    organization: "laviniadd"
    token:
         secure: $SONAR_TOKEN
install: true
cache:
   directories:
   - $HOME/.m2
   - $HOME/.sonar/cache

script:
 - git fetch --unshallow
 - mvn -f progetto/pom.xml clean verify -Pdocker -Pjacoco coveralls:report sonar:sonar

真不知道问题出在哪里。 我也尝试生成一个新的令牌并尝试直接使用它而不使用$SONAR_TOKEN,但没有任何改变。

先谢谢你。

EDIT 这是将 -X 添加到我的 travis 命令后的完整错误:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project progetto: Unable to load component class org.sonar.scanner.bootstrap.ScannerPluginInstaller: Unable to load component class org.sonar.scanner.bootstrap.PluginFiles: Unable to load component class org.sonar.scanner.bootstrap.GlobalConfiguration: Unable to load component class org.sonar.scanner.bootstrap.GlobalServerSettings: Not authorized. Please check the properties sonar.login and sonar.password. -> [Help 1]

看来你现在必须使用

加密声纳令牌
travis encrypt

https://docs.travis-ci.com/user/sonarcloud/

当令牌作为安全变量存储在 Travis 中时,它过去无需加密令牌即可工作。

或者,如果您使用变量存储未加密的令牌,您可以更改 .travis.yml 文件。

addons:
  sonarcloud:
    organization: utplsql
    token:
      # Put sonar connection token generated and encrypted.
      secure: ${SONAR_TOKEN}

收件人:

addons:
  sonarcloud:
    organization: utplsql
    token: ${SONAR_TOKEN}

这个解决方案对我有用。