SonarCloud - Javascript 的 Maven / bitbucket 项目没有扫描结果
SonarCloud - No scan results appearing for Javascript for maven / bitbucket project
我可能遗漏了一些明显的东西,但我似乎无法获得显示在 SonarCloud 中的 java 脚本的扫描结果。该存储库 95% 是 angular 应用程序,5% java 代码。 java代码扫描是出现在SonarCloud中,但实际上我只需要扫描angular应用程序中的java脚本。
很明显我们已连接到 SonarCloud,但 java 脚本没有任何显示。
我在pom.xml文件中添加了<sonar.language>js</sonar.language>
,效果是SonarCloud中根本没有出现任何扫描信息,大概是因为这个属性取消了对任何语言的扫描除 java脚本外,java脚本扫描配置不正确。
我只想扫描 angular 项目并在 SonarCloud 中报告结果。通过扫描构建 angular 项目的 dist/portal
目录,或者通过扫描 src/app
.
中的底层 Typescript 文件
如果java码也扫了就好了。
感谢您提供的任何帮助或指点。
- 使用的 ALM:带 Maven 的 Bitbucket
- 版本库语言:java、javascript(只需要扫描javascript)
- 观察到错误:SonarCloud
中没有出现 java 脚本的扫描结果
存储库的目录结构为:
- src
- app
- [rest of angular code]
- e2e
- [testing files]
- deploy
- pom.xml
- [java code for the deploy]
- bitbucket-pipelines.yml
这是pipeline.yml,使用maven到运行sonarcloud的步骤:
caches:
sonar: ~/.sonar/cache
steps:
- step: &buildArtifacts
name: Build and test
image:
name: [[NAME]]
aws:
access-key: $AWS_ACCESS_KEY
secret-key: $AWS_SECRET_KEY
caches:
- maven
- sonar
script:
- source prepare_environment.sh
- mvn -e clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
artifacts:
- artifact/**
这是 deploy/
目录中 pom.xml
内的属性:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<sonar.language>js</sonar.language>
<sonar.sources>${project.basedir}/../dist/portal</sonar.sources>
</properties>
扫描的最佳选择JS/TS 是自定义管道。
如果您不关心 Java 代码,只需要扫描 Javascript 和 Typescript,那么在 Bitbucket Cloud 上使用 scanner for CLI is probably the best bet, and even more specifically, using the scan pipe 最容易配置。您根本不需要使用 Maven。
在您的 bitbucket-pipelines
YAML 文件中,删除(或注释掉)在您的 &buildArtifacts
步骤中对 org.sonarsource.scanner
的引用:
mvn -e clean verify # org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
然后为 运行 管道创建一个新步骤:
- step: &buildAndTestSonarCloud
name: Analyze with SonarCloud
caches:
- node
- sonar
script:
- npm update && npm install
- pipe: sonarsource/sonarcloud-scan:0.1.5
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources=src/app'
SONAR_SCANNER_OPTS: -Xmx512m
DEBUG: "false"
您可能还需要通过以下方式扩展可用于该步骤的内存:
definitions:
services:
docker:
memory: 2048
最后,调用你的步骤:
pipelines:
default:
- step: *buildAndTestSonarCloud
- step: *buildArtifacts
应该可以。你应该在 JS/TS.
上 运行ning
如果您还想 运行 单元测试 和 让 sonarcloud 跟踪您的测试覆盖率,请在 npm update
行下方添加:
- npm run test -- --code-coverage --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox
这些 EXTRA_ARGS
为您的文件结构配置:
'-Dsonar.tests=src -Dsonar.test.inclusions="**/testing/**,**/*.spec.ts" -Dsonar.typescript.lcov.reportPaths=coverage/lcov.info'
这对我有用,应该可以处理完整的配置。
注意:这不会查看存储库中的 Java 代码。如果您 需要 Java 代码也被扫描,您将需要一个更复杂的 Maven 实现。
我可能遗漏了一些明显的东西,但我似乎无法获得显示在 SonarCloud 中的 java 脚本的扫描结果。该存储库 95% 是 angular 应用程序,5% java 代码。 java代码扫描是出现在SonarCloud中,但实际上我只需要扫描angular应用程序中的java脚本。
很明显我们已连接到 SonarCloud,但 java 脚本没有任何显示。
我在pom.xml文件中添加了<sonar.language>js</sonar.language>
,效果是SonarCloud中根本没有出现任何扫描信息,大概是因为这个属性取消了对任何语言的扫描除 java脚本外,java脚本扫描配置不正确。
我只想扫描 angular 项目并在 SonarCloud 中报告结果。通过扫描构建 angular 项目的 dist/portal
目录,或者通过扫描 src/app
.
如果java码也扫了就好了。
感谢您提供的任何帮助或指点。
- 使用的 ALM:带 Maven 的 Bitbucket
- 版本库语言:java、javascript(只需要扫描javascript)
- 观察到错误:SonarCloud 中没有出现 java 脚本的扫描结果
存储库的目录结构为:
- src
- app
- [rest of angular code]
- e2e
- [testing files]
- deploy
- pom.xml
- [java code for the deploy]
- bitbucket-pipelines.yml
这是pipeline.yml,使用maven到运行sonarcloud的步骤:
caches:
sonar: ~/.sonar/cache
steps:
- step: &buildArtifacts
name: Build and test
image:
name: [[NAME]]
aws:
access-key: $AWS_ACCESS_KEY
secret-key: $AWS_SECRET_KEY
caches:
- maven
- sonar
script:
- source prepare_environment.sh
- mvn -e clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
artifacts:
- artifact/**
这是 deploy/
目录中 pom.xml
内的属性:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<sonar.language>js</sonar.language>
<sonar.sources>${project.basedir}/../dist/portal</sonar.sources>
</properties>
扫描的最佳选择JS/TS 是自定义管道。
如果您不关心 Java 代码,只需要扫描 Javascript 和 Typescript,那么在 Bitbucket Cloud 上使用 scanner for CLI is probably the best bet, and even more specifically, using the scan pipe 最容易配置。您根本不需要使用 Maven。
在您的 bitbucket-pipelines
YAML 文件中,删除(或注释掉)在您的 &buildArtifacts
步骤中对 org.sonarsource.scanner
的引用:
mvn -e clean verify # org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
然后为 运行 管道创建一个新步骤:
- step: &buildAndTestSonarCloud
name: Analyze with SonarCloud
caches:
- node
- sonar
script:
- npm update && npm install
- pipe: sonarsource/sonarcloud-scan:0.1.5
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources=src/app'
SONAR_SCANNER_OPTS: -Xmx512m
DEBUG: "false"
您可能还需要通过以下方式扩展可用于该步骤的内存:
definitions:
services:
docker:
memory: 2048
最后,调用你的步骤:
pipelines:
default:
- step: *buildAndTestSonarCloud
- step: *buildArtifacts
应该可以。你应该在 JS/TS.
上 运行ning如果您还想 运行 单元测试 和 让 sonarcloud 跟踪您的测试覆盖率,请在 npm update
行下方添加:
- npm run test -- --code-coverage --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox
这些 EXTRA_ARGS
为您的文件结构配置:
'-Dsonar.tests=src -Dsonar.test.inclusions="**/testing/**,**/*.spec.ts" -Dsonar.typescript.lcov.reportPaths=coverage/lcov.info'
这对我有用,应该可以处理完整的配置。
注意:这不会查看存储库中的 Java 代码。如果您 需要 Java 代码也被扫描,您将需要一个更复杂的 Maven 实现。