5

我们在 Visual Studio 2015 中使用SonarLintStyleCop分析器。这些在开发过程中工作得很好,但想知道是否可以在 Jenkins 构建期间运行它们?

我见过 SonarLint.Runner,所以我假设这是可能的。

4

1 回答 1

2

我对 Jenkins 不是很熟悉,但您始终可以将分析器作为 NuGet 包安装到项目中,并让它们在 MsBuild 构建中生成警告和错误:

  1. 将以下 2 个 NuGet 包安装到您要分析的项目中:SonarAnalyzer.CSharpStyleCop.Analyzers

安装了分析器的项目

  1. 如果您希望构建在出现警告时失败,可以选择配置各个规则的严重性并将警告视为错误。

  2. 使用 MSBuild 编译这样配置的项目将导致分析器警告和错误以与编译器错误和警告相同的方式出现。您也应该能够在 Jenkins 中以同样的方式对待它们:

    "D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj" (default target) (2) ->
    (CoreCompile target) ->
      Class1.cs(13,17): warning CS0219: The variable 'a' is assigned but its value is never used [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(1,1): warning SA1652: Enable XML documentation output [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(1,1): warning SA1633: The file header is missing or not located at the top of the file. [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(13,23): warning SA1002: Semicolons must not be preceded by a space. [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(1,1): warning SA1200: Using directive must appear within a namespace declaration [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(2,1): warning SA1200: Using directive must appear within a namespace declaration [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(3,1): warning SA1200: Using directive must appear within a namespace declaration [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(4,1): warning SA1200: Using directive must appear within a namespace declaration [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(5,1): warning SA1200: Using directive must appear within a namespace declaration [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(1,1): warning SA1652: Enable XML documentation output [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(1,1): warning SA1633: The file header is missing or not located at the top of the file. [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(5,77): warning SA1028: Code must not contain trailing whitespace [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(17,76): warning SA1028: Code must not contain trailing whitespace [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(18,74): warning SA1028: Code must not contain trailing whitespace [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(28,22): warning SA1028: Code must not contain trailing whitespace [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Properties\AssemblyInfo.cs(32,84): warning SA1028: Code must not contain trailing whitespace [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(13,19): warning S1854: Remove this useless assignment to local variable "a". [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
      Class1.cs(13,17): warning S1481: Remove this unused "a" local variable. [D:\Users\Damir\Temp\SO_36412838_Analyzers\SO_36412838_Analyzers\SO_36412838_Analyzers.csproj]
    
        18 Warning(s)
        0 Error(s)
    
于 2016-04-08T20:13:26.047 回答