首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何配置SonarCloud

如何配置SonarCloud
EN

Stack Overflow用户
提问于 2017-09-28 06:40:43
回答 2查看 20.1K关注 0票数 10

我有一个java项目,我想将它与SonarCloud集成,我遵循以下正式步骤:

使用SonarQube扫描仪#检查代码 在检查代码之前,您需要:

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

添加我的travis.yml文件

代码语言:javascript
复制
 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

其中SONAR_TOKEN是特拉维斯CI上的一个变量,指向来自SonarCloud的密钥(它没有加密)。

从SonarCloud添加权限

但是,当我启动travis构建时,我有以下错误:

代码语言:javascript
复制
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.

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-09-29 06:47:19

在SonarCloud上配置项目的正式入口点是“开始”页面

  • 您将看到,对于Maven项目,根本不需要来创建sonar-project.properties文件
  • 您甚至可以找到一个指向示例Maven项目的链接,该链接在SonarCloud上进行分析。
票数 10
EN

Stack Overflow用户

发布于 2017-09-28 17:31:16

最后我找到了解决办法。在根路径中,您必须添加yml文件:

sonar-project.properties

代码语言:javascript
复制
# Required metadata
sonar.projectKey=java-sonar-runner-simple:master
sonar.projectName=Rss-service
sonar.projectVersion=1.0

# Comma-separated paths to directories with sources (required)
sonar.sources=/microservice-application/rss-reader-service/src/main/java
sonar.java.binaries=/microservice-application/rss-reader-service/target/classes

# Language
sonar.language=java

# Encoding of the source files
sonar.sourceEncoding=UTF-8

在travis.yml中,我添加: script:

代码语言:javascript
复制
  # other script steps might be done before running the actual analysis
  - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar

编辑

声纳-投射。没有必要。只有maven的目标才有意义。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46462540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档