CIRCLE_PR_NUMBER missing from environment variables

This is a follow up from https://twitter.com/atticoos/status/726648787976876032

I notice my builds from a branch within a PR does not contain the environment variable CIRCLE_PR_NUMBER.

It does contain CI_PULL_REUQEST, which contains the link to the PR. I am currently parsing this to get the PR number for my automated CI testing deployments (pr123.builds.xyz.com) - which is less than ideal.

My flow:

  • Push branch to the remote
  • Push triggers the CI
  • Open pull request
    – Unfortunately the build has already ran from the push, so it’s unlikely it has a PR context since the PR is opened after the push
  • Push another commit to the branch that is now part of a PR
  • Now the CI_PULL_REQUEST shows up, but not the CIRCLE_PR_NUMBER

How do I get CIRCLE_PR_NUMBER to show up?

And ideally I’d like to see a build start when the PR is opened too, but from research, that does not appear to be supported.

1 Like

Same question. +1

Same question here also +1

Not really a solution, but as a stop-gap, I’ve added the following to my environments:

run:
  name: Set PR number
  command: |
      echo 'export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"' >> $BASH_ENV
      source $BASH_ENV
      echo $CIRCLE_PR_NUMBER

The format "${A:-$B}" means "$A" if available, "$B", otherwise. And "${B##*/}" removes everything up to and including the final slash from "$B". Thus, if they re-add the more authoritative CIRCLE_PR_NUMBER, I’ll use it over my parsed guess.

4 Likes