Analysis running in Azure Pipeline ignoring file exclusions

I’ve set an Azure pipeline step for SonarQube Cloud.

I’ve added properties for exclusions:
Here is the content of the Additional Properties field:

sonar.exclusions="**/Migrations/**,**/wwwroot/**,**/*.ruleset"
sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml"
sonar.coverage.exclusions="**/Migrations/**,**/*.Tests/**,**/*.TestDoubles/**,**/*.TestHarness/**"

During the analysis, the files in the sonar exclusions are not being excluded.
Here is the extract from the logs of the analysis step:

    2019-03-01T20:00:56.9053195Z INFO: Indexing files of module 'DnD5eTools'
    2019-03-01T20:00:56.9053576Z INFO:   Base dir: D:\a\1\s
    2019-03-01T20:00:56.9053809Z INFO:   Excluded sources: **/Migrations/**,**/wwwroot/**
    2019-03-01T20:00:56.9054099Z INFO:   Excluded sources for coverage: **/Migrations/**,**/*.Tests/**,**/*.TestDoubles/**,**/*.TestHarness/**
    2019-03-01T20:00:56.9054318Z INFO: 1748 files indexed
    2019-03-01T20:00:56.9054523Z INFO: 0 files ignored because of inclusion/exclusion patterns

That is from the remote analysis.

In the local server, the analysis of the same project the files are excluded.
Here is the extract:

    INFO: Indexing files of module 'DnD5eTools-SonarQube'
    INFO:   Base dir: C:\Projects\DnD5eTools
    INFO:   Excluded sources: **/Migrations/**, **/wwwroot/**
    INFO:   Excluded sources for coverage: **/Migrations/**, **/*.Tests/**, **/*.TestDoubles/**, **/*.TestHarness/**
    INFO: 756 files indexed
    INFO: 1280 files ignored because of inclusion/exclusion patterns

Please help me understand what is wrong.

Andre

Here is the generated YAML:

steps:
    - task: SonarSource.sonarcloud.--------------------GUID------------------.SonarCloudPrepare@1
        displayName: 'Prepare analysis on SonarCloud'
        inputs:
        SonarCloud: SonarCloud
        organization: '-------------'
        projectKey: '-----------------------'
        projectName: DnD5eTools
        extraProperties: |
            sonar.exclusions="**/Migrations/**,**/wwwroot/**,**/*.ruleset"
            sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml"
            sonar.coverage.exclusions="**/Migrations/**,**/*.Tests/**,**/*.TestDoubles/**,**/*.TestHarness/**"
1 Like

Did you have any luck with this? We are having this happen for some of our projects too…

No luck at all and no answer from SonarQube also.

Andre, since it seems that this is working on your local server, can you tell us:

  • Which version of SonarQube you are using locally
  • Which version of the SonarQube extension and/or which version of the Scanner for MSBuild you are using locally

This should help us troubleshoot this.

has anyone been able to configure exclusions on Azure Pipelines? i am getting the same issue where files are not being ignored :frowning:

What properties are you setting?

As an example, I excluded all .css files from analysis in an Azure DevOps pipeline by setting the following exclusion in the Prepare Analysis step:

image

You can compare the results on SonarCloud:
Analysis with exclusions
Analysis without exclusions

If you want to exclude entire directories, the docs suggest that the exclusion pattern needs to end with /*
e.g.

**/Migrations/* rather than **/Migrations/**

1 Like

A post was split to a new topic: Exclusions in Azure Pipelines

I’ve tried the following under the SonarCloudPrepare@1 task in a YAML pipeline with no joy…

      extraProperties: |
        sonar.exclusions=**.js,**.css,**.scss

      extraProperties: |
        sonar.exclusions="**.js,**.css,**.scss"

      extraProperties: |
        sonar.exclusions='**.js,**.css,**.scss'

…nothing appears under the General Settings > Files > Source File Exclusions under the project

I suggest a review of this tasks capabilities

I am having the same issue.

I am using the Azure Pipelines Classic UI, but here is the YAML from my prepare step:

steps:
- task: SonarSource.sonarqube.<guid>.SonarQubePrepare@4
  displayName: 'Prepare analysis on SonarQube'
  inputs:
    SonarQube: 'My SonarQube Service Connection'
    scannerMode: CLI
    configMode: manual
    cliProjectKey: 'My.WebApp_Frontend'
    cliProjectVersion: '$(Build.BuildId)'
    cliSources: '$(System.DefaultWorkingDirectory)/src/My.WebApp'
    extraProperties: |
     # Additional properties that will be passed to the scanner, 
     # Put one key=value per line, example:
     sonar.exclusions=wwwroot/**/*, custom_typings/**/*, node_modules/**/*
     sonar.test.exclusions=test/**/*

Note, I have also tried excluding with:

  • wwwroot/**
  • custom_typings/**
  • test/**
  • '$(System.DefaultWorkingDirectory)/src/My.WebApp/wwwroot/**
  • '$(System.DefaultWorkingDirectory)/src/My.WebApp/custom_typings/**
  • '$(System.DefaultWorkingDirectory)/src/My.WebApp/test/**.

Logs:

15:41:48.292 INFO: Indexing files...
15:41:48.292 INFO: Project configuration:
15:41:48.292 INFO:   Excluded sources: wwwroot/**/*, custom_typings/**/*, node_modules/**/*
15:41:48.292 INFO:   Excluded tests: test/**/*
...
15:41:49.183 DEBUG: 4331 non excluded files in this Git repository
...
15:41:55.073 INFO: 4096 files indexed
15:41:55.073 INFO: 0 files ignored because of inclusion/exclusion patterns
15:41:55.073 INFO: 1 file ignored because of scm ignore settings

Which results in:

(Don’t judge us, this is our initial scan. :sweat_smile:)

Any tips for first-time configurators would be appreciated. My current next step is to try with a sonar-project.properties file.

I was able to get it working before testing wih sonar-project.properties file. I changed the exclusions to:

  • src/Referral.WebApp/wwwroot/**/*
  • src/Referral.WebApp/custom_typings/**/*
  • src/Referral.WebApp/node_modules/**/*

and these directories were successfully excluded from the scan:

17:26:09.204 INFO: 3564 files indexed
17:26:09.204 INFO: 548 files ignored because of inclusion/exclusion patterns
17:26:09.204 INFO: 1 file ignored because of scm ignore settings

For some reason I thought the exclusion paths were relative to the sonar.sources path, but that is wrong. Per the Narrowing the Focus documentation:

Paths are relative to the project base directory.

The final question I have lies around the sonar.test.exclusions property… what does this property actually do? I am going to move my final exclusion from that to sonar.exclusions because I don’t want these files to show up at all.

Hi @ahaleiii

As per documentation from Narrowing the Focus:

  • Source File Exclusions - to exclude source code files
  • Test File Exclusions - to exclude test files

How are source code and test code considerated? From Analysis Parameters:

sonar.sources Comma-separated paths to directories containing main source files.
sonar.tests Comma-separated paths to directories containing test source files.

And for dotnet specifically, the Scanner for .NET has logic to categorize which projects are tests - you can read more about that here.