Build only pull request to a specific branch


#1

Is there a way for me to build (and thus run my deployment) on branch X only when it has a pull request to branch master ? (I want my trigger for the build + deployment will be pull request to master from branch Release-x.y.z)


Only build Pull Requests targetting specific branch
#2

You may blacklist branches from being built in CircleCI. This example
excludes gh-pages from being built in circle:

general:
  branches:
    ignore:
      - gh-pages # list of branches to ignore
      - /release\/.*/ # or ignore regexes

You may also whitelist branches, so only whitelisted branches will trigger a build.
This example limit builds in circle to master and feature-.* branches:

general:
  branches:
    only:
      - master # list of branches to build
      - /feature-.*/ # or regexes

Any pull requests affecting those branches will trigger as well. I like to use the required status checks feature on GitHub for added protection.

Ref: https://circleci.com/docs/1.0/configuration/#branches


#3

this is not what i’ve asked.
i know you can black list branches but that’s not enough.
i build for example only brances with 'Release in the name: /Release-[1-9].[0-9].[0-9]/ however i want special behavior if i have a pull request from this branch to ‘master’ i know circle ci gets webhooks for pull requests, however i want to know how can i get some of the information in my build namly how to know if this build was issued due to pull request and if this pull request is into ‘master’. CAN i do that ???


#4

I apoligize if I am misunderstanding.

I believe you can get what you are looking for if you whitelist only master and the release branches using regex.

To see if this is a pull request you should be able to use $CI_PULL_REQUEST and $CIRCLE_BRANCH in your checks.

Ref: https://circleci.com/docs/1.0/environment-variables/#build-details


#5

CI_PULL_REQUEST will give me the name, which is cool, but how do i know to which branch this pull request is intended ? how will i know it’s into master ? i might be able to query using the name the gitub API but i was hoping to get his information from circle since i’m sure it arrives in the webhook.


#6

I believe this one will show as master if that’s where the PR is headed to.


#7

OK, i’ve tested this issue using an example github project and a pull request.
you supply the url for the pull request on github so assuming i have a token i can query github for the pull request details, however the CIRCLE_BRANCH for the pull request build is ‘new_branch’ which is my topic branch, not master into which this pull request is being merged. You do not include this information in the ENV even though you do ave it in the webhook which is a real shame.

For most of what i need i actually need to use curl and scripts to get the info i need and not your own platform.


Need a way to get dest branch on pull request buulds
#8

I’m sorry I was mistaken. I’ve created a feature request. Question though, you say the data exists in the web hook, do you happen to know what web hook this is?

I took a look at https://developer.github.com/v3/activity/events/types/#pushevent, but I didn’t see any sign of a branch mentioned, or even if it was a pull request.


#9

it’s not that events, https://developer.github.com/v3/activity/events/types/#pullrequestevent.
take a look in the payload on “head” and “base” keys, the “ref” key inside them points to those branches


Need a way to get dest branch on pull request buulds
#10

I’d like point out my support for a feature like this. It’s even more important on the iOS side, where overall build time is restricted per account. It’s also a common build pattern supported by Travis and Team City

Basically our build process is:

  • Every change on master is built with one set of rules. (Build, Test, distribute)
  • Every change on a branch with an open PR is built with another set of rules. (Build, Test)

Currently we are just doing this based on branch name, but this is burning into our build minutes much quicker than we want.

The closest I can get to this functionality is to check for an environment variable (CI_PULL_REQUEST) and no-op the build. By that I mean spin up the VM, increment the build number, but don’t do anything useful (IE: No build / test). This helps our minutes spent, but is pretty ugly and disappointing to explain.

Thanks

Brian


#11

+1 on this feature request. The workflow for my team only requires tests to run against PRs and the current setup is consuming build minutes much more quickly than I’d like.

I have recently transitioned to Circle from Travis. This plus an environment matrix are the two features I miss most.


#12

Thanks for your feedback.

I have opened an associated feature request here.


#13

@drazisil actually

Any pull requests affecting those branches will trigger as well. I like to use the required status checks79 feature on GitHub for added protection.

That doesn’t work.
I wanted that exact behaviour, run builds on PRs and branches affecting that branch but also on that branch. I can’t get that second part working.


#14