SonarQube MSBuild fails to exclude files

后端 未结 3 1056
遥遥无期
遥遥无期 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: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 = """
        
            
            true
        
    """
    
    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')
    

提交回复
热议问题