使用TeamCity和Github构建pull请求到特定的分支 [英] Build pull requests to specific branch using TeamCity and Github

查看:445
本文介绍了使用TeamCity和Github构建pull请求到特定的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望TeamCity为特定目标分支构建所有请求,例如 develop

所以,我想构建下面的请求:

  develop ... foo_branch 
develop ... bar_branch

和跳过此:

  master ... foo_branch 
master ... bar_branch

在TeamCity中,我可以定义分支规范来构建所有的请求:

  +:refs / pull / * / head 

或者按源代码分支定义过滤器:

   - :refs / heads /(spikes- *) 

但我需要按目标分支进行过滤。是否有可能?

解决方案

我已经编写了一个脚本来解决这个问题。它可以作为TC构建配置中的第一个构建步骤之一运行。该脚本将要求Github提供请求详细信息,解析响应并将源和目标分支名称注入TeamCity参数和环境变量。在接下来的构建步骤中,您可以基于这些变量中止构建或完成其他任何您需要的操作。

https://gist.github.com/dzzh/a6d8631e9617777fb5237bc9ec7b356b



对于脚本工作,你必须提交PR的id作为命令行参数。我们使用推荐的refspec(refs / pulls / * / head)来运行我们的构建,我从中提取PR id并用它调用脚本。


I want TeamCity to build all pull requests to specific target branch, e.g. develop.
So, I want to build following pull requests:

develop...foo_branch
develop...bar_branch

and skip this:

master...foo_branch
master...bar_branch

In TeamCity I can define branch specification to build all pull requests:

+:refs/pull/*/head

or define filter by source branch:

-:refs/heads/(spikes-*)

But I need filter by target branch. Is it possible?

解决方案

I've written a script to work around this issue. It can be run as one of the first build steps in TC's build configuration. The script will ask for pull request details from Github, parse the response and inject source and target branch names as TeamCity parameters and environment variables. In the next build steps, you'll be able to abort the build or do whatever else you need based on these variables.

https://gist.github.com/dzzh/a6d8631e9617777fb5237bc9ec7b356b

For the script to work, you'll have to submit PR's id as a command-line argument. We use the recommended refspec (refs/pulls/*/head) to run our builds, I extract the PR id from it and invoke the script with it.

这篇关于使用TeamCity和Github构建pull请求到特定的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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