Possible to detect branch being pulled into?

In our repo, we have main and develop as protected branches so no one can push directly to them, only open PRs to merge into them.

I’d like to set up a workflow based not on the branch the code is on (which I think pipeline.git.branch resolves to) but rather the branch the PR is trying to merge into. That way I can have cheap tests when merging to develop, but more expensive tests when merging into main.

But I just can’t figure out how or if CircleCI can do this.

:wave: Hi @mathomp4,

CircleCI doesn’t currently have a built-in environment variable or pipeline value that contains the pull-request destination branch name.

I recommend adding your vote to this open feature request. Alternatively, you could apply this workaround suggested by another user.

That said, note that when a build is triggered upon a pull-request merge (as opposed to a pull-request creation), the CIRCLE_BRANCH built-in environment variable will contain the name of the destination branch.

However, keep in mind that a pull-request merge will only trigger a build if you merge into a default branch.
I wrote a default branch (rather than the default branch) because we have the ability to mark additional branches to be considered as default in the related CircleCI project.

Let me know if this helps.