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)

3 Likes

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

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.

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

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

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

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.

Thanks

Brian

8 Likes

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