Hi,
Could someone please assist me and share any thoughts on how to exclude some of projects during Analysis.
In my solution I have 4 projects, out of which I need to skip Sonarqube analysis for 2 of them during TFS build Analysis.
I have already tried below methods which did not work for me.
Method1:
1. I have added below section on Sonarqube.Integration file under Targets folder (D:\SonarqubeMSBuildScanner\Targets)
<Project xmlns="
http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<!-- This target customises the SonarQube Scanner for MSBuild targets to limit the projects that are analysed.
Projects whose full path and file name do not match the specified filter will be marked as "excluded".
The regular expression uses the normal .NET regular expression syntax.
-->
<PropertyGroup Condition=" $(SonarQubeExclude) == '' AND $(SQPathFilter) != '' ">
<MatchesSQPathFilter Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(MSBuildProjectFullPath), $(SQPathFilter), System.Text.RegularExpressions.RegexOptions.IgnoreCase)) ">true</MatchesSQPathFilter>
<SonarQubeExclude Condition="$(MatchesSQPathFilter) = 'true' " >true</SonarQubeExclude>
</PropertyGroup>
</Project>
2. Next I have added an MSBuild argument using different combinations like below in my Build Definition as below, none of the below formats worked.
/p:SQPathFilter=$(SouceDir)\\dir1\dir2\\dir3\\<projectname>\\projectname.csproj
/p:SQPathFilter=$(SouceDir)\\dir1\dir2\\dir3\\<projectname>
(where $(SourceDir) is my default location in Build controller on to which my source code gets copied during Build time , <projectname> is one of the projects in a solution which I don't want to run the Analysis for.)
When I triggered Build, AboveProject (projectname) is not skipping from Analysis.
Not sure , am I doing anything wrong syntactically or could be something am missing here, please suggest me on how to fix this.
**********************************************************************
Below is the document , I got online and tried.
Excluding projects based on the file path
Depending on the layout of the projects on disk, it might be possible to specify the projects to analyse based on the file paths.
For example, suppose the projects above are laid out on disk as follows:
c:\Web\ProjectA
c:\Web\ProjectB
c:\Framework\ProjectC
c:\Framework\ProjectD
c:\Framework\ProjectX
The following custom targets file selects the projects to analyse based on the file path:
<Project xmlns="
http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<!-- This target customises the SonarQube Scanner for MSBuild targets to limit the projects that are analysed.
Projects whose full path and file name do not match the specified filter will be marked as "excluded".
The regular expression uses the normal .NET regular expression syntax.
-->
<PropertyGroup Condition=" $(SonarQubeExclude) == '' AND $(SQPathFilter) != '' ">
<MatchesSQPathFilter Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(MSBuildProjectFullPath), $(SQPathFilter), System.Text.RegularExpressions.RegexOptions.IgnoreCase)) ">true</MatchesSQPathFilter>
<SonarQubeExclude Condition="$(MatchesSQPathFilter) != 'true' " >true</SonarQubeExclude>
</PropertyGroup>
</Project>
This targets file would allow the projects to be filtered as follows:
REM Only analyse the web projects, regardless of which projects are included in the solution
REM Note: the backslash in the supplied path is escaped
msbuild Solution1.sln /p:SQPathFilter=c:\\web
REM Only analyse the framework projects
msbuild Solution2.sln /p:SQPathFilter=c:\\framework
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Method 2:
I have directly tried from Sonarqube dashboard.
project --> Administration --> settings --> Analysis scope -->
Sonar File exclusions **/<myproject>/**
Basically I am trying to skip the Analysis as per folder paths mentioned, this method also got failed.
Please suggest.
Thanks,
Praveen