Search code examples
jenkinssonarqubesonar-runnersonarqube-scan

Excluding contents of a folder anywhere in directory tree from analysis in Sonar


I have a ASP.net project that i need to run SonarQube analysis on and i have configured it with Jenkins to run the analysis. The analysis is running fine but it is including the bower_components and node_modules i have in the project. The way the project is structured there are multiple node_modules and bower_component folders in the projects folder structure. So i need to exclude them all in a pattern. I have added a SonarQubeSetting section to the .csproj file and i have the current values for exclusion.

<Target Name="BeforeBuild">
   <ItemGroup>
      <SonarQubeSetting Include="sonar.exclusions">
          <Value>**\main-built.js,**\template-build.js,**\kendo*.js,**\bower_components\*,**\node_modules\*</Value>    
      </SonarQubeSetting>
   </ItemGroup>
</Target>

Using **\bower_components\* **\node_modules\* did not work and the libraries are still picked up and scanned. How can i exclude folder (in my case node_modules & bower_components) content regardless of its location in the directory structure in sonar?


Solution

  • The last time I setup Sonar, I am pretty sure the sonar.exclusion property worked as expected... Perhaps your naming pattern is a little off. For example, how about a ** at the end rather than *. See this answer for examples and answers when using naming patterns.