在TFS构建中执行Sonar-runner

3
我如何让TFS(Team Foundation Server)在持续集成结束时运行sonar-runner命令? 信息:TFS 2013,Windows Server 2008 R2,sonar-runner 2.3。

以下是否是您需要的答案,Carvalho先生?如果是的话,请接受它! - Nam G VU
2个回答

3
唯一的执行构建过程中任意命令的方法是向BuildProcessTemplate添加InvokeProcess活动。这并不像一开始看起来那么困难。
  1. 复制位于团队项目的/BuildProcessTemplates文件夹中的DefaultTemplate.xaml。将其命名为您喜欢的任何名称 - SonarRunnerTemplate.xaml等。

  2. 在Visual Studio中打开新模板

  3. 点击右上角的“折叠全部”以便于导航到正确的活动。

  4. 浏览至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

  5. 在“Then”框中,您将看到一个Copy Files to Drop Location活动。暂时将其移动到“Else”框中。

  6. 从工具箱中添加一个Sequence活动到(现在为空的)Then框中

  7. 将您之前移动的Copy Files to Drop Location(我们之前移动了它)放回到您刚刚添加到Then框中的Sequence活动中。

  8. 从工具箱中添加一个InvokeProcess活动,以在“Copy Files to Drop Location”活动之后运行所需的Sonar runner命令。

  9. 打开InvokeProcess活动的属性。 FileName字段是您需要执行的命令。在本例中,要执行Sonar runner的命令。可能最容易编写一个批处理或PowerShell脚本来运行Sonar...然后调用它。

  10. 保存构建过程模板并将其添加到TFS。您可以然后使用此模板作为您的构建定义

这种方法的一个问题是在InvokeProcess命令返回之前,构建不会“完成”。因此,如果您的Sonar运行时间非常长(我知道我曾经见过它耗时超过24小时的大型代码库),则构建需要很长时间才能完成。可以通过使您的脚本异步生成Sonar进程来缓解这种情况。

0

现在有一种官方的方法可以让MsBuild和TeamBuild与SonarQube配合使用,这是微软和SonarQube之间合作的一部分。您可以在SonarQube网站上找到所有细节:

http://www.sonarqube.org/announcing-sonarqube-integration-with-msbuild-and-team-build/

而在微软ALM网站上:

http://blogs.msdn.com/b/visualstudioalm/archive/2015/04/28/technical-debt-management-announcing-sonarqube-integration-with-msbuild-and-team-build.aspx

此外,ALM Rangers 还准备了文档,介绍了如何安装 SonarQube 并将其集成到现有的 TFS 服务器中:

https://vsarguidance.codeplex.com/downloads/get/1452516


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接