Search code examples
azure-devopssonarqubesonarcloud

ignoring specific files/folders with sonar.exclusions


I have an ASP.NET MVC5 web app running on an Azure Devops CI/CD pipeline which includes SonarCloud for static code analyses. I am trying to ignore all 3rd party files such as Javascript/JQuery libraries which are throwing up a lot of "Bugs" and "Code Smells".

I would like to hide these files specifically:

INFO: 4/9 files analyzed, current file: BookingSystem/Scripts/jquery-3.3.1.js

I have tried various sonar.exclusions in Administration > General Settings > Analysis Scope > Files > Source File Exclusions and none have hidden the specific folders:

sonar.exclusions=**\Scripts\**
sonar.exclusions=Scripts\**
sonar.exclusions=**\Scripts**
sonar.exclusions=**\BookingSystem\Scripts\**

picture of logs

Can anyone tell me which format to use please?


Solution

  • I did not configure the sonar.exclusions via the UI like what you mentioned. You can try with below method in azure devops.

    Just specify it in task definition(Sample):

    - task: SonarCloudPrepare@1
      displayName: 'Prepare analysis on SonarCloud'
      inputs:
        SonarCloud: 'SonarCloud'
        organization: 'xxxx'
        scannerMode: 'MSBuild'
        projectKey: 'xxxx'
        extraProperties: sonar.exclusions=**/Properties/**
    

    Here is what my project structure:

    enter image description here

    See this Properties folder was ignored successfully:

    enter image description here