Sonarcloud 未被授权使用 Travis CI 和 Maven

Sonarcloud is not authorized using Travis CI and Maven

我在 Github 上有一个实验项目,用于练习 CI 服务集成。我很难使用 Sonarcloud。

我都关注了Tavis CI + Sonarcloud tutorial and Maven example。 Mz 的第一个混淆是从令牌和属性文件开始的,而第一个来源建议创建 sonar-project.properties 文件,而 Maven 示例源没有任何内容。这里的文档很不清楚。

我忽略了属性文件并完成了以下步骤

  1. sonarcloud.io 上为我的项目生成了令牌:e53.....239

  2. travis-encrypt.github.io 上的加密令牌,因为这是 Windows 用户最舒适的方式。以下 2 个输入导致 g3s.....+Q=:

    • NicharNET/Gistintex
    • SONAR_TOKEN="e53...239" - 我尝试在引号和不引号之间都换行。
  3. 已添加到设置 -> 环境变量键 SONAR_TOKEN 生成的 Sonarcloud 令牌的值 e53...239.

  4. 已使用安全令牌完成travis.yml:

    language: java
    sudo: false
    jdk: oraclejdk8
    
    addons:
        sonarcloud:
        organization: "nicharnet-github"
        token:
            secure: "g3sLTdS597mklh1I9HgXr71NRCiOk2n9I41PL2wklnAidwibfocyEcWvSQxjmbhNTjdrcW0cAfzh73Ago8hwfdloraryDY9Ng9L1runxayShtPOqZMPI6nz8zUwLaDfqJVwXWv6A3xICOMFl0UhvF351GPErHhrUO7YIa8el3kESeotYy7kkTzeQ7BA239y7EVFw8H4OCW2gjP2G/InxKnlXfNjgQA3GsnZdJ3uWO3No5kwt5ybfuCCV42cp/UczLIzNbo0RW9Z9jBl5IFMzJaUQUfWV3Pp5QEPmpB7Anr/4W1EtjJPjpSIC/+jBmbrkvC/CSzzTPjaH9LzEQ5m4F5JpRw01blqgKH/153qfs1jRgZK6WVRuhe7yAATHCO/IM0DM+kC0mUJTcXKyv9pRm93E4wp+KzdHYy0LdA83wFgMmvlB8pcm20ImAe7B2SBFx5TGtETa6ea6k2BS+DfBXe6sLBnrl1zZB8nxCDnYiwT1BJFxizgv3EJ6Krjd3cSSxr6PGnXDD/yTeFNJarpMbA+wR6AQetJ89LiDBXYiw6GPgWk/A4vUDIsIaXGqCpydeZHkr2ufS1Ap4yYS0Um2GeDeQXTsBTSCg7BViFgduUI1NPYT1avKg7b64nsdpdjBVofOvzJsgiT66WlaJmt23BUCJsnmXwwEcW1387b4G+Q="
    
    script:
        - mvn clean install org.jacoco:jacoco-maven-plugin:prepare-agent sonar:sonar
    
  5. 提交更改并将其推送到存储库中,Travis CI 开始工作并导致:

    Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.1.1168:sonar (default-cli) on project gistintex: Not authorized. Please check the properties sonar.login and sonar.password.

可以在我的 Travis CI build 上找到错误。我做错了什么?

我浏览了Error using Travis CI with Sonarcloud: Not authorized. Please check the properties sonar.login and sonar.password SO question and Travis CI Sonarqube analysis article, which unfortunately didn't help me though. My GitHub project source


我尝试将这些插件添加到 pom.xml 和 运行 本地分析:

运行 这在我的机器上产生了正确的 Sonarcloud analysis:

mvn sonar:sonar \
   -Dsonar.organization=nicharnet-github \
   -Dsonar.host.url=https://sonarcloud.io \
   -Dsonar.login=e53.....239

但是,我的目标是 运行 使用 Travis CI 在每个提交的版本之后进行分析。我确定我做错了密钥加密,但我不知道到底是什么。

密钥加密问题通常发生在您对 travis.com 而不是 travis.org

执行没有登录命令的生成时

为了在每次提交时 运行,您可以将您的存储库与 SonarCloud Scan 连接,在您的 sonarcloud.io 项目页面中生成一个秘密,您会在那里找到修改您的 . travis.yml

如果你使用travis.org

travis encrypt <YOUR_SONAR_SECRET>

如果你使用travis.com

travis login --pro

然后像这样生成你的令牌:

travis encrypt --pro <YOUR_SONAR_SECRET>

最后,您需要将流水线指令添加到您的 .travis.yml 文件

在应该触发时检查您的 Travis CI 回购设置

这里有一些相关链接:

Error using Travis CI with Sonarcloud: Not authorized. Please check the properties sonar.login and sonar.password

https://docs.travis-ci.com/user/encryption-keys/#usage

https://github.com/marketplace/actions/sonarcloud-scan

https://sonarcloud.io/documentation/integrations/github/