我可以采取哪些步骤来优化 TeamCity 中的构建时间?
我目前正在尝试减少在 TeamCity 中编译和单元测试项目所需的时间。
目前我的项目大约需要 5 到 8 分钟才能构建。
它的作用是:
- 清理所有现有文件
- 编译每个项目
- 创建安装程序
完成后,单元测试将启动,运行大约需要 2 分钟。
它的作用是:
- 清理任何现有文件
- 编译每个项目
- 运行所有单元测试
现在,运行单元测试只需要 5 秒......因此清理和编译步骤大约需要 2 分钟......以及创建安装程序步骤约3至6分钟。
我的第一个问题是:是否有任何方法可以配置 team city,以便在运行单元测试时不必再次执行清理和编译步骤。 我相信我们这样做的主要原因是因为项目构建和单元测试可以由不同的构建代理运行。
我的第二个问题是:5 到 8 分钟的项目构建时间是否合理? 有没有办法优化解决方案中项目的编译以及安装程序的创建?
如果我可以提供任何其他详细信息,请告诉我,这些细节可能会帮助您指出优化构建或保持原样的正确方向。
更新以回答一些问题Nate:
当您在 TeamCity 之外运行构建时,它会在单元测试之前再次进行清理/编译吗? 不,因为当您在自己的计算机上运行它时,您可以指定要运行构建脚本的哪些部分。 我们有清理、编译、单元测试等部分,这些部分在团队城市中针对项目构建与单元测试运行的指定方式有所不同。
如果是这样,你能让构建在测试之前不这样做吗? 我们目前不这样做的原因是,当使用不同的构建代理时,单元测试所需的文件将不可用,因此会失败。
你用什么来构建你的项目? 我们使用 Nant 来构建项目,使用 wix 来安装程序,使用 NUnit 和 NCover 来进行单元测试和覆盖率报告。
您使用什么源代码控制系统? 颠覆
I'm currently trying to reduce the time taken to compile and unit test projects in TeamCity.
Currently my project takes about between 5 to 8 minutes to build.
What it does is:
- Clean any existing files
- Compile each project
- Create the installer
Once that is done the unit tests are kicked off and it takes about 2 minutes to run.
What it does is:
- Clean any existing files
- Compile each project
- Run all the unit tests
Now, running the unit tests only takes 5 seconds....so the clean and compile step takes about 2 minutes....and the create installer step about 3 to 6 minutes.
My first question is: Is there any way to configure team city so that it doesn't have to do the clean and compile steps again when it runs the unit tests. I believe the main reason why we have it that way is because the project build and unit tests can be run by different build agents.
My second question is: Is 5 to 8 minutes a reasonable time for a project build to take? Are there ways to optimize the compile of the projects in the solution as well as the installer creation?
Please let me know if there are any additional details I can supply that might help you to point me in the right direction of either optimising the build or just leaving things as they are.
Update to answer some questions from Nate:
When you run the build outside TeamCity, does it do a clean/compile again before the unit tests? No, because when you run it on your own machine you can specify which parts of the build script to run. We have sections for clean, compile, unit-test etc which get specified differently in team city for project build vs unit test running.
If so, can you make the build not do that before the tests? The reason we don't do this at the moment is because when different build agents are used the files needed for the unit test would not be available and thus would fail.
What are you using to build your project? we use Nant to build our project, wix for the installer, and NUnit and NCover for the unit tests and coverage reports.
What source control system are you using? Subversion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于 #1:当您在 TeamCity 之外运行构建时,它是否会在单元测试之前再次进行清理/编译? 如果是这样,你能让构建在测试之前不这样做吗?
你用什么来构建你的项目? 您使用什么源代码控制系统?
考虑的另一个选择是拥有多个构建配置。 在我的工作中,我们有多种配置。 每次提交后运行的一个。 它进行清理/编译和一些快速测试。 然后我们有一个夜间配置来执行清理/编译和所有测试。 你能做这样的事吗?
Regarding #1: When you run the build outside TeamCity, does it do a clean/compile again before the unit tests? If so, can you make the build not do that before the tests?
What are you using to build your project? What source control system are you using?
Another option consider is having multiple build configurations. At my work, we have several configurations. One that runs after each commit. It does a clean/compile and some quick tests. We then have a nightly config that does a clean/compile and all the tests. Can you do something like that?
根据经验,您应该使提交时触发的构建尽可能短,因此您应该尝试将构建配置重构为精简的提交构建,并每小时左右运行一次当前配置。
As a rule of thumb you should keep the build that is triggered on commit as short as posible, so you should try to refactor the build configuration into a slim on commit build, and run the current configuration once every hour or so.