Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build pull requests to specific branch using TeamCity and Github

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?

like image 556
Dmitriy Startsev Avatar asked Sep 09 '15 15:09

Dmitriy Startsev


1 Answers

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.

like image 77
Zmicier Zaleznicenka Avatar answered Oct 16 '22 12:10

Zmicier Zaleznicenka