我有java项目,我想将它与SonarCloud集成我遵循官方步骤:
使用SonarQube扫描仪检查代码#
在检查代码之前,您需要:
- 在SonarCloud上为您的帐户创建用户身份验证令牌.
- 加密此令牌travis加密abcdef0123456789或在存储库设置中定义SONAR_TOKEN
- 找到您想要推送项目的SonarCloud.io组织并获取其密钥
- 为您的项目创建一个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 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将SonarCloud徽章添加到我的README.
但是当我这样做时

Run Code Online (Sandbox Code Playgroud)
徽章本身看起来不错,但它不允许转到sonarcloud项目而是导致camo.githubusercontent.com.
我应该使用哪个链接来访问该SonarCloud项目?
谢谢。
我想知道是否可以向我们的 SonarCloud 实例添加自定义规则或修改现有规则(如https://docs.sonarqube.org/display/DEV/Adding+Coding+Rules 中所述)。
我们已经在几个私有项目上设置了 SonarCloud,我想 - 例如 - 修改规则“php:S1068 - 应删除未使用的私有字段”。在我们使用的框架中,一个名为“$db”不应标记为“未使用”,因为该框架通过反射使用该变量。
是否可以在 SonarCloud 中添加/修改此类规则?
我已经使用“.NET Core with SonarCloud”模板在 Azure Devops 中为我的 .NET Core 项目设置了管道。当我构建时,分析会在 SonarCloud 中运行,但代码覆盖率为 0%(我的解决方案中有测试)。
无论我对构建进行什么配置调整,我都无法使代码覆盖率正常工作。
我错过了什么?
我遇到了这篇文章和https://dejanstojanovic.net/aspnet/2019/may/publishing-code-analysis-to-sonarcloud-from-azure-build-pipeline/ //dejanstojanovic.net/aspnet/2019/may/publishing-code-analysis-to-sonarcloud-from-azure-build-pipeline/ 实现了其中描述的powershell脚本,但我仍然没有SonarCloud 中的代码覆盖率
我尝试使用这里描述的床罩,但仍然没有乐趣 https://gunnarpeipman.com/aspnet/azure-devops-code-coverage/
我的管道由以下任务组成
我的测试任务是这样配置的:
参数: --configuration $(BuildConfiguration)
发布测试结果和代码覆盖率 - 选中
在运行代码分析任务的控制台中,我得到:
10:43:54.7 Fetching code coverage report information from TFS...
10:43:54.702 Attempting to locate a test results (.trx) file...
10:43:54.753 Looking for TRX files in: C:\\TFSBuilds\\TJPYHG04-GHJ01\\_work\\475\\TestResults
10:43:54.755 No test results files found
10:43:54.81 Did not find …Run Code Online (Sandbox Code Playgroud) 我刚刚结束了我与 Jenkins 的 GitHub 集成,这样每次我将代码提交到我的 GitHub 存储库时,Jenkins 都会自动构建。现在我也在尝试集成 SonarCloud,但我还没有成功。我不想与本地 SonarQube 服务器集成,我真的需要 SonarCloud 让我的团队在每次 Jenkins 构建时检查它。
我不确定是否应该在本地分析项目来实现这一点,或者我是否可以分析我的 Jenkins 服务器或 GitHub 存储库并获得我想要的结果,因为我找不到任何文档。
任何人都可以指出我正确的方向吗?
谢谢!
我有一个包含 Javascript 和 Typescript 文件的项目。我正在使用 SonarCloud 从 Azure DevOps 管道分析这个项目。
我在构建管道中设置任务“准备分析配置”,如下所示:
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'Sonarcloud'
organization: 'MyOrg'
scannerMode: 'CLI'
configMode: 'manual'
cliProjectKey: 'My key'
cliProjectName: 'My name'
cliSources: '.'
Run Code Online (Sandbox Code Playgroud)
运行管道时,我的管道在Sonar Cloud Analysis步骤中出现以下错误
INFO: Found 1 tsconfig.json file(s): [/home/vsts/work/1/s/tsconfig.json]
##[error]ERROR: Cannot find module 'typescript'
##[error]ERROR: TypeScript dependency was not found and it is required for analysis.
ERROR: Install TypeScript in the project directory or use NODE_PATH env. variable to set TypeScript location, if it's located outside …Run Code Online (Sandbox Code Playgroud) 早些时候我使用sonar-maven-plugin version 3.2过,当声纳质量门失败时,构建也会失败。现在我用的是sonar-maven-plugin version 3.7.0.1746,不会出现这样的情况。即使质量门失败,maven 构建也会成功。现在,当我在 pom.xml 中使用版本 3.2 时,会出现错误
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar (default-cli) on project maven-webapp: Unable to execute SonarQube: Fail to download libraries from server -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
使用时sonar-maven-plugin version 3.7.0.1746不会出现上述错误。
这就是我在 Pom.xml 中添加插件的方法
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我还了解到,在 3.2 版本中,有一些诸如org.sonar.plugins.buildbreaker.QualityGateBreaker.
现在怎么办呢?我使用https://sonarcloud.io/进行声纳。
我第一次为 SonarCloud 构建了一个包含 X 个模块的 maven 项目。该sonar.projectKey值需要是唯一的,因此我将其设置为${project.groupId}:{$project.artifactId},以便每个模块生成它。之后,运行 CI,这是响应消息:
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project ${project.groupId}:${project.artifactId}: Could not find a default branch to fall back on. -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
我怀疑这是因为我没有在我的“组织”上用那个键创建一个项目,但问题是我有多个模块。事实上,我有X个。我还应该为每个要扫描的模块创建一个项目吗?sonarqube 插件不应该处理吗?
在我的Android 应用程序项目中,我使用的是sonarqube-gradle-plugin:3.3OpenJDK 11。当我运行时,./gradlew sonarqube控制台会输出以下内容。从那时起它就不再存在了。自从我使用 Java 11 以来,它可能是新的。
这是我的 SonarQube 配置:sonarqube.gradle
\n> Task :buildSrc:jar\n:jar: No valid plugin descriptors were found in META-INF/gradle-plugins\nConfiguration on demand is an incubating feature.\n\n> Task :app:sonarqube\nStatus ERROR: org.eclipse.jdt.core code=4 Could not retrieve declared methods org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files\nStatus ERROR: org.eclipse.jdt.core code=4 Could not retrieve declared methods org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.String cannot be resolved. It is …Run Code Online (Sandbox Code Playgroud) 正如以下公告所指出的,SonarSource 终止了对使用 11 版之前的 Java 版本运行代码分析器的支持:
2021 年 1 月 - 将分析移至 Java 11
扫描仪环境中安装的 Java 版本必须在 2021 年 2 月 1 日之前至少升级到 Java 11。Java 11 之前的版本已被弃用,使用它们的扫描仪将在该日期停止运行。
此外,2021 年 1 月 11 日至 2021 年 1 月 15 日期间将会出现限电,在此期间,使用低于 11 的 Java 版本的扫描仪运行的首次分析将失败。为了避免这种不便,您应该在 2021 年 1 月 11 日之前升级。
这里讨论的 Java 安装特指在运行 SonarCloud 扫描仪分析工具的上下文中安装和使用的 JDK 或 JRE。这可能是您本地的构建环境或您的 Cl 服务。
这不会对项目代码所针对的 Java 版本产生任何影响。您仍然可以分析目标版本低于 11 的 Java 项目。
我尝试搜索有关如何运行 bitbucket 管道以使用 java 11 分析器执行 SonarScanner 分析的完整示例,但目标代码使用 java 11 之前的版本(例如 java …
sonarcloud ×10
sonarqube ×4
java ×3
azure-devops ×2
github ×2
java-11 ×2
maven ×2
.net-core ×1
android ×1
encryption ×1
gradle ×1
jenkins ×1
markdown ×1
maven-plugin ×1
travis-ci ×1