[英]SonarQube MSBuild fails to exclude files
I am running an analysis using msbuild on debian, using the following command:我在 debian 上使用 msbuild 运行分析,使用以下命令:
mono /msbuild/SonarQube.Scanner.MSBuild.exe begin /d:sonar.login=<sonarqubetoken> /d:sonar.host.url=https://<my-server> /d:sonar.exclusions=test/**/* /k:<my-project-key>
However in the end
command:但是
end
命令:
INFO: Index files
INFO: Excluded sources:
INFO: test/**/*
INFO: 17 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: Quality profile for cs: Sonar way
INFO: Excluded sources for coverage:
INFO: test/**
and the analysis on the UI of my server includes files from test/
folder.并且对我的服务器 UI 的分析包括来自
test/
文件夹的文件。
Why does it fail to ignore the specific files?为什么无法忽略特定文件?
Using SonarQube 6.7
and sonar-scanner:3.3
使用
SonarQube 6.7
和sonar-scanner:3.3
Exclusions are difficult to set correctly from the analysis side, as demonstrated by your attempt.正如您的尝试所证明的那样,很难从分析方面正确设置排除项。 Your best bet is to set these from the UI.
最好的办法是从 UI 设置这些。
The only way I have managed to get around this situation is by adding the following line to the .csproj
file of the projects I want excluded我设法解决这种情况的唯一方法是
.csproj
下行添加到我要排除的项目的.csproj
文件中
<!-- Exclude the project from SonarQube analysis -->
<SonarQubeExclude>true</SonarQubeExclude>
I had the same problem with after I upgraded to SonarQube Scanner for MSBuild 4.0.2升级到 MSBuild 4.0.2 的 SonarQube 扫描仪后,我遇到了同样的问题
As pkaramol stated and by looking at the docs [ 1 , 2 ] this seems to be the only solution because sonar.exclusions matches only files in each project folder and not the solution folder.正如 pkaramol 所述,通过查看文档 [ 1 , 2 ],这似乎是唯一的解决方案,因为 sonar.exclusions 仅匹配每个项目文件夹中的文件,而不匹配解决方案文件夹。 I wrote a python (>= 3.5) script for my CI which adds those lines to projects I want to be excluded.
我为我的 CI 编写了一个 python (>= 3.5) 脚本,它将这些行添加到我想要排除的项目中。
import os
import glob
import shutil
SOURCEDIR_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
SQ_EXCLUDE_TAG = """
<PropertyGroup>
<!-- Exclude the project from analysis -->
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>
"""
def add_sq_exclude_tag(project_name):
search_path = os.path.join(SOURCEDIR_PATH, '**', '{}.csproj'.format(project_name))
for file_path in glob.iglob(search_path, recursive=True):
with open(file_path, 'r', encoding='utf8') as outfile:
lines = outfile.readlines()
project_end_tag = lines[-1]
lines[-1] = SQ_EXCLUDE_TAG
lines.append(project_end_tag)
with open(file_path, 'w', encoding='utf8') as outfile:
outfile.writelines(lines)
print('Added sonarqube exclude tag to {}'.format(file_path))
if __name__ == '__main__':
add_sq_exclude_tag('*csprojFileConatainsThisString*')
add_sq_exclude_tag('exactCsprojFileNameWithoutFileEnding')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.