Only build Pull Requests targetting specific branch

envars
github

#1

I’m pulling this feature request from the following thread.

In order to provide a way to build pull requests which only target a specific branch, the target branch will have to be included in the payload from the vcs. I’m not sure if it is or not, or if we can make this information available via an environment variable. (i.e. $CIRCLE_BRANCH)


Create a CIRCLE_TARGET_BRANCH envar
Build only pull request to a specific branch
#2

It is possible to set circle to get webhooks for pull requests with the right permissions , which i think u already ask and get.
https://developer.github.com/webhooks/
you get the following json(example from the github api site):
https://developer.github.com/v3/activity/events/types/#pullrequestevent

so you get ‘head’ json object which is the branch the PR was opened for and ‘base’ which is where the PR is going to be merged.
you can expose BOTH as env variable using ~/.circlerc
you can register for this webhook just like u do for regular commit pushes, only u ned now to diffrenciate and it’s up to the user to decide what to do.


#3

I would definitely want this, especially for managing builds on OSX which are time delimited for the month. Right now there are very few controls to empower customers to have control over when and how they make OSX builds.


#4

+1 … Post must be at least 10 characters


#5

My workaround if anyone finds it useful, I use a build step like this:

  name: Merge to target branch
  command: |
    if [[ -n ${CIRCLE_PR_NUMBER} ]]
    then
    curl -L "https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64" \
      -o jq
    chmod +x jq
    url="https://api.github.com/repos/$ORG/$PROJECT/pulls/$CIRCLE_PR_NUMBER?access_token=$GITHUB_TOKEN"
    target_branch=$(
      curl "$url" | ./jq '.base.ref' | tr -d '"'
    )
    git config user.name circleci
    git config user.email circleci@example.com
    git pull origin $target_branch
    fi

#6