【发布时间】:2019-04-13 10:02:25
【问题描述】:
我有 2 个Jenkins shared libraries,其中包含要扫描的 groovy 文件。两个项目都使用 maven 使用相同的 sonarqube 调用,但在一个项目中扫描了 groovy 文件,而在另一个项目中则没有
Sonarqube 通话
...
String scanCmd = "mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar " +
"-f pom.xml " +
"-Dsonar.branch=%GIT_BRANCH% " +
"-Dsonar.test.inclusions=**/*Test*/** " +
"-Dsonar.exclusions=**/*Test*/** " +
"-Dsonar.skipDesign=true "
bat scanCmd
...
如果重要的话,我们使用的是 5.6.6 版
声纳扫描仪配置
声纳配置在包含声纳属性的父 pom 中
....
<properties>
<!-- Sonar -->
<sonar.sources>src,vars</sonar.sources>
<sonar.inclusions>**/**</sonar.inclusions>
</properties>
....
两个项目 (pom.xml) 都使用这个父 pom,即相同的声纳属性p>
项目 1:0 个文件编入索引
项目结构如下:
D:.
│ .gitignore
│ Jenkinsfile
│ pom.xml
│ README.md
│
├───src
│ └───ch
│ └───swisscard
│ └───jenkins
│ └───pipeline
│ └───util
│ PipelineRabbitMQ.groovy
│
└───vars
ciPipeline.groovy
所以有两个 groovy 文件应该被扫描,但日志文件显示 0 个文件被索引:
[INFO] Base dir: D:\jenkins\tools\ci-home\workspace\rabbitmq-ci-pipeline_master-2CYM2JXOI6CJM2T4MSNQTNPWY7LRY7PTSC3OG74TSX2Q2WNKXUSQ
[INFO] Working dir: d:\jenkins\tools\ci-home\workspace\rabbitmq-ci-pipeline_master-2CYM2JXOI6CJM2T4MSNQTNPWY7LRY7PTSC3OG74TSX2Q2WNKXUSQ\target\sonar
[INFO] Source paths: src, vars
[INFO] Binary dirs: target/classes
[INFO] Source encoding: UTF-8, default locale: en_US_US
[INFO] Index files
[INFO] Included sources:
[INFO] **/**
[INFO] Excluded sources:
[INFO] **/target/**/*
[INFO] **/*Test*/**
[INFO] **/*Test*/**
[INFO] Included tests:
[INFO] **/*Test*/**
[INFO] 0 files indexed
[INFO] 0 files ignored because of inclusion/exclusion patterns
项目 2:正确扫描文件
第二个项目结构如下:
D:.
│ .gitignore
│ Jenkinsfile
│ pom.xml
├───src
│ └───main
│ │ Utils.groovy
└───vars
checkQualityGate.groovy
defaultBuildApplication.groovy
ciPipeline.groovy
这里的日志文件表明所有文件都被扫描了:
[INFO] Load server rules (done) | time=98ms
[INFO] Base dir: D:\jenkins\tools\ci-home\workspace\pipeline_feature_sonar-scan-D6GRAK5PLQOMGCOOH2T6QP6BP4LA6O3LP23UC7VBSSL3RORI4ZXQ
[INFO] Working dir: d:\jenkins\tools\ci-home\workspace\pipeline_feature_sonar-scan-D6GRAK5PLQOMGCOOH2T6QP6BP4LA6O3LP23UC7VBSSL3RORI4ZXQ\target\sonar
[INFO] Source paths: src, vars
[INFO] Source encoding: UTF-8, default locale: en_US_US
[INFO] Index files
[INFO] Included sources:
[INFO] **/**
[INFO] Excluded sources:
[INFO] **/target/**/*
[INFO] **/*Test*/**
[INFO] **/*Test*/**
[INFO] Included tests:
[INFO] **/*Test*/**
[INFO] 5 files indexed
[INFO] 0 files ignored because of inclusion/exclusion patterns
问题/疑问
显然这两个项目具有相同的配置和相似的结构,但是一个被扫描而另一个未被扫描。目前我不明白为什么? 我检查了其他对我没有帮助的主题
- 我没有明确设置
sonar.basedir,但根据日志,基本目录没问题
【问题讨论】:
-
上个时期发生了什么变化?你升级了一些插件吗?计划升级到最新的 LTS 版本:6.7.5。
-
目前还没有。我使用相同版本的声纳扫描仪和相同的声纳服务器在同一个 Jenkins 上运行这两个项目。已计划升级,但不会在未来几周内完成
-
请在调试模式下执行命令(
-X)并添加更多日志(从扫描仪执行开始)。 -
我也有同样的问题,不知道怎么解决。
-
同样的问题,目前有解决方案吗?
标签: maven jenkins sonarqube sonarqube-scan