Sonar Runner未在TeamCity

时间:2016-06-15 16:12:01

标签: teamcity sonar-runner

Sonar Runner step我们正在尝试为TeamCity中的项目(模块)设置Sonar。我们有以下构建步骤: 1)Nuget安装 2)Visual Studio sln 3)检查(.Net) 4)Sonar Runner

在Sonar Runner步骤中,它无法获取该文件。请参见图像2 unable to find that xml file

请指点我如何让它选择xml文件。

1 个答案:

答案 0 :(得分:3)

这里的主要技巧是将报告XML传递给SonarQube运行器 - 可以使用/output resharper选项完成(参见下面的步骤2)。虽然还有一些事情可能毁了你的一天,所以我编写了一个完整的程序。

  1. 首先确保正确配置SonarQube Server以接受Resharper数据。您需要安装Resharper和C#插件,并使用Resharper规则配置质量配置文件。要检查配置,我建议按照Resharper plugin documentation中的说明手动运行分析。

  2. 然后配置您的Inspections(.Net)TeamCity构建步骤以在众所周知的位置创建报告XML:打开高级选项并在“Additional inspectCode.exe参数:”字段中添加/output=%system.teamcity.build.tempDir%\inspectReport.xml(或任何其他位置)。 重要!该步骤将失败,因为它希望报告位于默认位置(请参阅issue on YouTrack)。所有后续步骤都需要Execute step: if some of the previous steps failed选项才能运行

  3. 在SonarQube Runner步骤中打开高级选项并在“其他参数:”字段中添加以下两行(将pathToSolutionFile替换为实际路径):

    -Dsonar.resharper.cs.reportPath=%system.teamcity.build.tempDir%\inspectReport.xml
    -Dsonar.resharper.solutionFile=pathToSolutionFile
    
  4. 最后,要查看TeamCity UI中的检查报告,还要添加一个新的命令行构建步骤:

    echo "##teamcity[importData path='%system.teamcity.build.tempDir%\inspect.xml' type='ReSharperInspectCode']"