SonarQube MSBuild fails to exclude files

后端 未结 3 1057
遥遥无期
遥遥无期 2021-01-21 14:41

I am running an analysis using msbuild on debian, using the following command:

 mono /msbuild/SonarQube.Scanner.MSBuild.exe begin /d:sonar.login=

        
相关标签:
3条回答
  • 2021-01-21 15:19

    The only way I have managed to get around this situation is by adding the following line to the .csproj file of the projects I want excluded

    <!-- Exclude the project from SonarQube analysis -->
    <SonarQubeExclude>true</SonarQubeExclude>
    
    0 讨论(0)
  • 2021-01-21 15:24

    Exclusions are difficult to set correctly from the analysis side, as demonstrated by your attempt. Your best bet is to set these from the UI.

    0 讨论(0)
  • 2021-01-21 15:32

    I had the same problem with after I upgraded to SonarQube Scanner for MSBuild 4.0.2

    As pkaramol stated and by looking at the docs [1,2] this seems to be the only solution because sonar.exclusions matches only files in each project folder and not the solution folder. I wrote a python (>= 3.5) script for my CI which adds those lines to projects I want to be excluded.

    import os
    import glob
    import shutil
    
    SOURCEDIR_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    
    SQ_EXCLUDE_TAG = """
        <PropertyGroup>
            <!-- Exclude the project from analysis -->
            <SonarQubeExclude>true</SonarQubeExclude>
        </PropertyGroup>
    """
    
    def add_sq_exclude_tag(project_name):
        search_path = os.path.join(SOURCEDIR_PATH, '**', '{}.csproj'.format(project_name))
        for file_path in glob.iglob(search_path, recursive=True):
            with open(file_path, 'r', encoding='utf8') as outfile:
                lines = outfile.readlines()
                project_end_tag = lines[-1]
                lines[-1] = SQ_EXCLUDE_TAG
                lines.append(project_end_tag)
            with open(file_path, 'w', encoding='utf8') as outfile:
                outfile.writelines(lines)
            print('Added sonarqube exclude tag to {}'.format(file_path))
    
    
    if __name__ == '__main__':
        add_sq_exclude_tag('*csprojFileConatainsThisString*')
        add_sq_exclude_tag('exactCsprojFileNameWithoutFileEnding')
    
    0 讨论(0)
提交回复
热议问题