2

如何在持续集成中构建 TFS(Team Foundation Server)结束时运行 sonar-runner 的命令?信息:TFS 2013、Windows Server 2008 R2、声纳运行器 2.3

4

2 回答 2

2

在构建过程中执行任意命令的唯一方法是将 InvokeProcess 活动添加到 BuildProcessTemplate。这并不像起初看起来那么困难。

  1. 制作位于团队项目的 /BuildProcessTemplates 文件夹中的 DefaultTemplate.xaml 的副本。将其命名为您想要的任何名称 - SonarRunnerTemplate.xaml 或其他名称。

  2. 在 Visual Studio 中打开新模板

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

  4. 在子句中浏览到Process> Sequence> Run On Agent> > > >Try Compule, Test, and Associate Changesets and Work ItemsFinallyRevert Workspace and Copy FilesIf DropBuild And DropLocation is Set

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

  6. 将工具箱中的活动添加Sequence到(现在为空)然后框

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

  8. InvokeProcess从工具箱中添加一个活动以在“复制文件到放置位置”活动之后运行

  9. 打开 InvokeProcess 活动的属性。该FileName字段是您需要执行的命令。在这种情况下,执行 Sonar runner 的命令。编写运行 Sonar 的批处理或 powershell 脚本可能是最简单的......然后调用它。

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

这种方法的一个问题是,在 InvokeProcess 命令返回之前,构建不会“完成”。因此,如果您的声纳运行需要很长时间(我知道我已经看到大型代码库需要超过 24 小时),那么构建将需要很长时间才能完成。这可以通过让脚本异步生成 Sonar 进程来缓解。

于 2013-08-20T19:42:37.753 回答
0

作为 Microsoft 和 SonarQube 合作的一部分,现在有一种官方方法可以让 MsBuild 和 TeamBuild 与 SonarQube 一起工作。您可以在 SonarQube 网站上找到所有详细信息:

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

在 Microsoft ALM 网站上:

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

ALM 管理员还准备了文档,描述了如何安装 SonarQube 并将其与现有 TFS 服务器集成:

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

于 2015-05-05T09:13:47.233 回答