复制位于团队项目的/BuildProcessTemplates文件夹中的DefaultTemplate.xaml。将其命名为您喜欢的任何名称 - SonarRunnerTemplate.xaml等。
在Visual Studio中打开新模板
点击右上角的“折叠全部”以便于导航到正确的活动。
浏览至Process
>Sequence
>Run On Agent
>Try Compile, Test, and Associate Changesets and Work Items
>在Finally
子句>Revert Workspace and Copy Files
>If DropBuild And DropLocation is Set
在“Then”框中,您将看到一个Copy Files to Drop Location
活动。暂时将其移动到“Else”框中。
从工具箱中添加一个Sequence
活动到(现在为空的)Then框中
将您之前移动的Copy Files to Drop Location
(我们之前移动了它)放回到您刚刚添加到Then框中的Sequence活动中。
从工具箱中添加一个InvokeProcess
活动,以在“Copy Files to Drop Location”活动之后运行所需的Sonar runner命令。
打开InvokeProcess活动的属性。 FileName字段是您需要执行的命令。在本例中,要执行Sonar runner的命令。可能最容易编写一个批处理或PowerShell脚本来运行Sonar...然后调用它。
保存构建过程模板并将其添加到TFS。您可以然后使用此模板作为您的构建定义。
现在有一种官方的方法可以让MsBuild和TeamBuild与SonarQube配合使用,这是微软和SonarQube之间合作的一部分。您可以在SonarQube网站上找到所有细节:
http://www.sonarqube.org/announcing-sonarqube-integration-with-msbuild-and-team-build/
而在微软ALM网站上:
此外,ALM Rangers 还准备了文档,介绍了如何安装 SonarQube 并将其集成到现有的 TFS 服务器中: