Exclude Project during TFS Build Analysis. - Not Working

498 views
Skip to first unread message

Praveen Davuluri

unread,
May 9, 2017, 6:38:51 PM5/9/17
to SonarQube
 
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






Julien HENRY

unread,
May 12, 2017, 6:00:06 AM5/12/17
to SonarQube

Praveen Davuluri

unread,
May 12, 2017, 7:00:47 PM5/12/17
to SonarQube
Hi Julien,

Thank you for your reply, we have gone through this document.

The solution mentioned in the document requires all project files to be checked in again after adding exclusion property in to project files.
Could you please  suggest any other flexible option that doesn't require any checkouts and check-ins and also we don't want any manual updates to the code or project files.

Thanks,
Praveen Davuluri
Reply all
Reply to author
Forward
0 new messages