如何配置SonarCloud

Xel*_*ian 6 java encryption travis-ci sonarqube sonarcloud

我有java项目,我想将它与SonarCloud集成我遵循官方步骤:

使用SonarQube扫描仪检查代码#

在检查代码之前,您需要:

  1. 在SonarCloud上为您的帐户创建用户身份验证令牌.
  2. 加密此令牌travis加密abcdef0123456789或在存储库设置中定义SONAR_TOKEN
  3. 找到您想要推送项目的SonarCloud.io组织并获取其密钥
  4. 为您的项目创建一个sonar-project.properties文件(请参阅文档).然后将以下行添加到.travis.yml文件以触发分析:

在我的travis.yml文件中添加

 addons:
  sonarcloud:
    organization: "xelian-github"
    token:
      secure: ${SONAR_TOKEN}
    branches:
      - master
script:
  # other script steps might be done before running the actual analysis
  - sonar-scanner
Run Code Online (Sandbox Code Playgroud)

其中SONAR_TOKEN是Travis CI上的变量,指向SonarCloud的密钥.(它未加密). 在此输入图像描述 从SonarCloud我添加权限 在此输入图像描述

但是当我开始travis构建时,我有以下错误:

Setting environment variables from repository settings
$ export SONAR_TOKEN=[secure]

 ....
ERROR: Error during SonarQube Scanner execution
ERROR: You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the SonarQube server. Please contact your SonarQube administrator.
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
Run Code Online (Sandbox Code Playgroud)

在我看来,我的travis没有权限将结果上传到SonarCloud.是令牌中还是某些Sonar配置中的问题.

Fab*_*eam 8

在SonarCloud上配置项目的官方入口点是"入门"页面:

  • 您将看到,对于Maven项目,您根本不需要创建sonar-project.properties文件

  • 您甚至可以找到在SonarCloud上分析的示例Maven项目的链接