我按照 SonarQube 文档的说明进行操作。我按照说明将声纳库和声纳扫描仪安装到我的应用程序文件夹中。但让我的终端识别声纳扫描仪时遇到困难。我通过尝试以下操作检查了我的路径变量:
echo $PATH
Run Code Online (Sandbox Code Playgroud)
并得到...
/Users/Neptune/Applications/SonarQube/bin:/Users/Neptune/Applications/SonarScanner/bin:/Users/Neptune/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin :/sbin:/Applications/domino:/Library/TeX/texbin:/Library/Apple/usr/bin
这就是我的道路
export PATH="/Users/Neptune/Applications/SonarScanner/bin:$PATH"
export PATH="/Users/Neptune/Applications/SonarQube/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)
然后我把它改为:
export PATH="/Users/Neptune/Applications/SonarScanner/bin/sonar-scanner:$PATH"
Run Code Online (Sandbox Code Playgroud)
在每种方法之后,我重新启动了 shell,但仍然没有运气。然后我转到项目根目录,在其中安装了 python 代码并添加了一个 project.properties 文件,但我不知道这如何帮助终端将 sonar-scanner -h 识别为命令。有人可以帮忙吗?谢谢
SonarQube 为我启动,我能够启动 localhost:9000 服务器。它让 mac 识别声纳扫描仪是给我带来问题的原因。
编辑:我设法让声纳扫描仪工作。但这是一个非常痛苦的过程。我必须始终输入:
sh /Applications/SonarScanner/bin/sonar-scanner
Run Code Online (Sandbox Code Playgroud) 通过 Jenkins 运行声纳扫描仪时,我们收到以下错误消息。Jenkins 和 Sonarqube 已安装在 Window Server 2008 操作系统中。我也尝试在服务器中安装node.js,但仍然收到相同的错误消息。
我们缺少什么?为什么我们需要这个 Node.js 来进行分析?我们基本上是在分析 HTML 应用程序。尽管我们收到以下错误消息,但执行已成功完成。但我们正在尝试找到以下错误的根本原因。
ERROR: Error when running: 'node -v'. Is Node.js available during analysis?
org.sonarsource.nodejs.NodeCommandException: Error when running: 'node -v'. Is Node.js available during analysis?
at org.sonarsource.nodejs.NodeCommand.start(NodeCommand.java:77)
at org.sonarsource.nodejs.NodeCommandBuilderImpl.getVersion(NodeCommandBuilderImpl.java:171)
at org.sonarsource.nodejs.NodeCommandBuilderImpl.checkNodeCompatibility(NodeCommandBuilderImpl.java:144)
at org.sonarsource.nodejs.NodeCommandBuilderImpl.build(NodeCommandBuilderImpl.java:120)
at org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl.initNodeCommand(EslintBridgeServerImpl.java:129)
at org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl.startServer(EslintBridgeServerImpl.java:105)
at org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl.startServerLazily(EslintBridgeServerImpl.java:145)
at org.sonar.plugins.javascript.eslint.EslintBasedRulesSensor.execute(EslintBasedRulesSensor.java:92)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:359)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:354)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:317)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at …Run Code Online (Sandbox Code Playgroud) 当我运行 ng test --code-coverage,然后运行 sonar-scanner 时,仍然无法在声纳服务器上看到覆盖率报告。
我尝试使用 Angular 13 设置新项目并按照官方文档进行设置。还是没有运气。
我的声纳服务器版本:版本9.2.1(内部版本49989)
我的声纳扫描仪版本:4.7
我的 Karma 配置
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/lcov'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true, …Run Code Online (Sandbox Code Playgroud) 我在Windows机器上运行SonarQube Server和Jenkins实例.
我创建了Jenkins工作以使用SonarQube生成代码覆盖率报告.这个工作在Linux机器上运行
但后来我在詹金斯得到了错误
ERROR: Error during SonarQube Scanner execution
ERROR: Unable to execute SonarQube
ERROR: Caused by: Fail to get bootstrap index from server
ERROR: Caused by: Failed to connect to localhost/0:0:0:0:0:0:0:1:9000
Run Code Online (Sandbox Code Playgroud)
错误是正确的,因为我的服务器在Windows机器上运行而不是在Linux(127.0.0.1)上运行.
想知道如何解决这个问题?并在Windows上获得结果.可能吗 ?
我已经设置了 SonarQube 和 SonarScanner 并设法扫描了我的项目。我可以在屏幕上看到除代码覆盖率之外的指标,代码覆盖率始终为 0%。我错过了什么?
#----- Default SonarQube server
sonar.host.url=http://localhost:9000/sonar
#----- Default source code encoding
#sonar.sourceEncoding=UTF-8
# must be unique in a given SonarQube instance
sonar.projectKey=pwta
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=PWTA
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=client
sonar.language=ts
sonar.exclusions=**/node_modules/**
sonar.typescript.lcov.reportPaths=coverage/lcov.info
Run Code Online (Sandbox Code Playgroud)
以上是sonar-project.properties文件的摘录。位于coverage/lcov.info 的LCOV …
我开玩笑地写了一些单元测试。他们都成功了。能够查看jest生成的测试覆盖率报告
但我的 sonarqube 仪表板始终显示覆盖率 0%,但正在检测单元测试。
我正在使用jest-sonar-reporter来生成声纳消耗品格式的报告。
这是我的声纳属性文件
sonar.projectKey=skyflow-app
sonar.projectName=Skyflow App
sonar.host.url = http://localhost:9000
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.exclusions=**/node_modules/**,**/*.spec.ts, **/*.stories.tsx
sonar.tests=src
sonar.test.inclusions=**/*.test.tsx,**/*.test.ts
sonar.test.exclusions=**/*.stories.tsx
sonar.ts.tslintconfigpath=tslint.json
sonar.testExecutionReportPaths=testResults/sonar-report.xml
# sonar.coverageReportPaths = coverage/lcov.info
sonar.javascript.lcov.reportPaths = coverage/lcov.info
Run Code Online (Sandbox Code Playgroud)
请让我知道我哪里出错了。
我一直在尝试配置 sonarqube 以使用云构建触发器,并希望使用 bitnami 的 sonarqube 计算实例安装,但是当我使用本指南安装 sonar-scanner 时: https: //docs.sonarqube.org/latest/analysis/scan/ sonarscanner/,运行时sonar-scanner -h收到此错误“在 JAVA_HOME 或 PATH 中找不到“java”可执行文件”,我的 JAVA_HOME 是opt/bitnami/java,PATH 是opt/bitnami/java/bin帮助我解决我做错的问题,或者如果遗漏了什么。
bitnami google-compute-engine sonarqube sonarscanner google-cloud-build
我使用 Azure 管道来运行单元测试和 SonarQube 集成。当我使用 cobertura 进行单元测试时,我无法将代码覆盖率结果传递到 SonarQube,尽管我在管道日志中看到结果。然而,当我使用 OpenCover 时,同样的事情也会发生。
\n我还在管道日志中看到此警告,尽管我不确定这是否相关: \xe2\x80\x9cMissingblame information for the following files\xe2\x80\x9d
\n目前的管道如下所示
\n - task: DotNetCoreCLI@2\n inputs:\n command: \xe2\x80\x98test\xe2\x80\x99\n projects: | \n <test-proj>\n arguments: \xe2\x80\x98/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura\xe2\x80\x99\n displayName: \xe2\x80\x98Run Tests\xe2\x80\x99\n\n - task: SonarQubePrepare@4\n inputs: \n SonarQube: <Service-Endpoint>\n scannerMode: \xe2\x80\x98MSBuild\xe2\x80\x99\n projectKey: \xe2\x80\x98test:service\xe2\x80\x99\n projectName: \xe2\x80\x98test:service\xe2\x80\x99\n extraproperties: | \n sonar.flex.cobertura.reportPaths=$(Build.SourcesDirectory)/**/coverage.cobertura.xml \n \n - task: DotNetCoreCLI@2\n <Running DotNet build>\n\n - task: SonarAnalyze@4\n \nRun Code Online (Sandbox Code Playgroud)\n运行DotNet Test阶段时,测试结果在此路径中获得 -\n E:\\agent-5\\2\\s\\test\\ApiTest\\coverage.cobertura.xml
\n任何建议,将不胜感激。
\n我正在尝试使用在 Docker、操作系统:Windows 上本地运行的 SonarQube 和 SonarScanner 扫描某些项目的源代码。
通过在终端中提供下一个命令,我尝试使用 SonarScanner 运行容器,它应该扫描当前目录中的代码(SonarQube 实例在后台运行):
docker run \
--rm \
--network=host \
-e SONAR_HOST_URL="http://127.0.0.1:9000/" \
-e SONAR_LOGIN="...some token..." \
-v $PWD:/usr/src sonarsource/sonar-scanner-cli \
-Dsonar.projectKey=some-project-name
Run Code Online (Sandbox Code Playgroud)
之后,我收到“执行成功”消息,但 SonarQube 在“代码”选项卡中显示“未找到用于分析的代码文件”(统计信息也为空)。
我尝试添加-Dsonar.sources=some_subdirectory_which_exists_in_the_current_directory参数,这会导致“执行失败”消息和“基本目录中不存在该文件夹”消息。所以我认为容器只是无权访问项目文件,或者由于某种原因它不复制它们。
docker sonarqube sonarqube-scan docker-container sonarscanner
我正在试验 Visual Studio Code Remote。我想使用SonarScanner进行代码质量分析。我已按照指南在主机上安装了该工具,但是当我尝试从容器中使用它时,我得到:
# dotnet sonarscanner -h
No executable found matching command "dotnet-sonarscanner"
Run Code Online (Sandbox Code Playgroud)
在主机上:
$ dotnet sonarscanner -h
SonarScanner for MSBuild 4.7.1
Using the .NET Core version of the Scanner for MSBuild
Usage:
SonarScanner.MSBuild [begin|end] /key:project_key [/name:project_name] [/version:project_version] [/d:sonar.key=value] [/s:settings_file]
When executing the begin phase, at least the project key must be defined.
Other properties can dynamically be defined with '/d:'. For example, '/d:sonar.verbose=true'.
A settings file can be used to define properties. If no settings …Run Code Online (Sandbox Code Playgroud) 我将声纳和Jacoco用于我的Android应用程序代码覆盖率报告。我可以通过设置jacoco任务作业和Sonar作业,然后执行以下命令来成功部署它。
./gradlew clean jacocoTestReport (name of jacoco task)
./gradlew sonarqube (<- mark this)
Run Code Online (Sandbox Code Playgroud)
报告已成功生成,并显示到localhost:9000声纳服务器设置。
我听说了可用于执行相同任务的声纳扫描仪。
我的困惑是我应该在gradlew命令中使用sonar-scanner或sonarqube;它们如何彼此不同。
sonarscanner ×11
sonarqube ×10
docker ×2
angular ×1
angularjs ×1
azure ×1
azure-devops ×1
bitnami ×1
devops ×1
jenkins ×1
jestjs ×1
typescript ×1