Build only pull request to a specific branch

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)


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

      - 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:

      - 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.


1 Like

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 ???

1 Like

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.


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.

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

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.

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, but I didn’t see any sign of a branch mentioned, or even if it was a pull request.

it’s not that events,
take a look in the payload on “head” and “base” keys, the “ref” key inside them points to those branches

1 Like

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.




+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.

Thanks for your feedback.

I have opened an associated feature request here.

@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.