在功能分支上运行测试 [英] Running tests on feature branches

查看:127
本文介绍了在功能分支上运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个构建配置,其中包含连接到git分支 dev 的测试VCS根目录,3个构建步骤和1个触发器。这些是我的构建步骤:
$ b


  • 构建测试

  • 运行测试

  • Build&部署



我希望为分支 dev 运行所有这些构建步骤但只有两个(构建和运行测试)匹配特性/ * 的分支。我希望这将显示在我的构建配置下。因此,构建配置具有运行测试和部署的默认 dev 分支,但功能/ * 其他分支仅运行测试。



我该如何实现这一目标?



如果我添加 / refs /头/ /特征/ *)到分支规范(低于默认分支),这个工作完美,但它总是部署 - 我不想要。




编辑1:似乎有一个名为%teamcity.build.branch%的可用变量,您可以使用它。但是如何在部署步骤中执行条件来检查分支是否是 dev 分支。我不确定。



编辑2:还有一个变量名称%vcsroot.branch%,这是VCS根目录中缺省分支的名称。所以我们仍然需要一个条件来检查%teamcity.build.branch%变量是否等于%vcsroot.branch% ,然后运行部署步骤。

解决方案

实现您想要的方式是将构建拆分为2个构建并具有依赖关系它们之间。那么你可以在构建之间有单独的触发器。



因此,拆分构建,以便构建包含


  • 构建测试

  • 运行测试



包含


  • 构建&部署



让build B成为构建A的快照依赖。在检测到VCS签入时添加触发器以构建A.这将确保构建和测试在任何功能分支上运行。



在检测到VCS签入时还在构建B上添加触发器,但编辑规则以便排除功能分支。当检测到任何其他分支的检入时,构建B将启动,但它需要构建A才能首先完成,因此它将首先排队,如果构建A失败,则不会启动(假设您在选项中设置该构件)

更新
如果这太麻烦了,那么您可以发挥一些小把戏,但在Run测试和构建和部署,它调用命令行或PowerShell脚本。调用传入%teamcity.build.branch%的脚本,然后脚本可以检查是否使用 dev 调用它。和退出0 如果是这样并且退出-1 如果不是这样,那么这一步应该会失败并阻止部署。这将意味着构建看起来会失败,但会阻止您希望避免运行的步骤。如果这个步骤失败了,团队团队可能不会报告失败,我不确定你还有其他选择是你写一个脚本手动构建和部署,然后调用传递给%teamcity.build.branch%的脚本,如果它不是 dev ,则提前退出$ c>,只有在 dev 时才继续执行实际的构建和部署。这不会导致构建失败,但意味着你必须编写脚本来完成TeamCity为你做的事情。


I have a build configuration with a test VCS root that connects to git branch dev, 3 build steps and 1 trigger. These are my build steps:

  • Build tests
  • Run tests
  • Build & Deploy

I would like to run all of these build steps for branch dev but only two of them (build and run tests) for branches matching feature/*. I want this to be displayed under my build configuration. So the build configuration has a default dev branch that runs tests and deploys, but the feature/* additional branches only run tests.

How can I achieve this?

If I add /refs/heads/(feature/*) to the branch specification (below default branch), this works perfectly, but it always deploys - which I don't want.

Edit 1: There seems to be a variable available named %teamcity.build.branch% that you can use. But how to do a conditional in the deployment step to check if the branch is the dev branch. I'm not sure.

Edit 2: There is also a variable name %vcsroot.branch% that is the name of the default branch in the VCS root. So we still need a condition that checks if the %teamcity.build.branch% variable equals %vcsroot.branch%, then run the deployment step.

解决方案

The way to achieve what you want is to split your build into 2 builds and have dependencies between them. then you can have separate triggers between the builds.

So split the builds so you have build A which contains

  • Build tests
  • Run tests

and build B which contains

  • Build & Deploy

Give build B a snapshot dependency on build A.

Then add a trigger to build A when a VCS check-in is detected. This will ensure that the build and tests are run on any feature branch.

Also add a trigger on build B when a VCS check-in is detected, but edit the rules so that you exclude your feature branches. When a check-in on any other branch is detected build B will start, but it needs build A to finish first so it will queue that up first, and won't start if build A fails (assuming you set that in the options)

UPDATE If this is too much hassle then you might be able to play a small trick but creating a build step between Run tests and Build and Deploy which calls a command line or powershell script. Call the script passing in %teamcity.build.branch% and then the script can check if it was called with dev and Exit 0 if so and Exit -1 if not and this step should then fail the build and prevent the deploy. This will mean that the build will seem failed but will prevent the step you want to avoid from running. It may be possible to get teamcity not to report the build as failing if this step fails, I'm not certain

You other option is that you write a script which does the build and deploy manually and then call this script passing in the %teamcity.build.branch% and exit early if its not dev and only go on to do the actual build and deploy if it is dev. this won't result in a failed build but means you have to write scripts to do the things TeamCity is doing for you now.

这篇关于在功能分支上运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆