Pull request number



I’m trying to get the pull request number and detect if I’m on a pull request on a build.

When I look at the docs of the env vars:

I see:
CI__PULL_REQUEST to know I’m on a pull request
CIRCLE_PR_NUMBER to know the PR number I’m into

But none works. Any clue?


Hm, it should be. Do you happen to have a link to a public build or a circle.yml we could take a look at?


Nop, its private and I’m using only the build steps on the interface, no .yml

Here are the tests parameters:

wget http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip

unzip sonar-runner-dist-2.4.zip

if [ "$CIRCLE_PULL_REQUEST" = true ]; then sonar-runner-2.4/bin/sonar-runner -e -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=$CIRCLE_PR_NUMBER -Dsonar.github.repository=$REPO_SLUG -Dsonar.github.oauth=$GITHUB_TOKEN -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASS -Dsonar.host.url=$SONAR_HOST_URL; fi

I tried also with $CI_PULL_REQUEST

If condition is never filled


Something I ran into that may be your issue, env varibles arn’t bool, they are stored as string.

See if comparing to ‘true’ helps.


Thanks for your answer, but I’m unlucky nothing worked out, tried:

if [ "$CI_PULL_REQUEST" = "true" ];
if [ "$CIRCLE_PULL_REQUEST" = "true" ];
if [ "$CI_PULL_REQUEST" = true];
if [ "$CIRCLE_PULL_REQUEST" = true];


Sorry i didnt catch this before, but im pretty sure you should not be putting the varible in quotes.

Ref Is it possible to run deploy section with out the build


Strange thing is that:

if [ "$CIRCLE_BRANCH" = "develop" ];

Works fine


Its possible that its not working and a bug needs to be filed.

I would test with echo $CI_PULL_REQUEST to see if/what it is getting set to.


Thanks for your help, tried with:

if [ $CI_PULL_REQUEST = "true" ];
if [ $CIRCLE_PULL_REQUEST = "true" ];

None works :confused:


What does the echo command get you?


Thanks, more info here:


So I have to parse it and extract the number to get the PR number, because it will never be true. Should have tested more, thanks


So final code is (because $CIRCLE_PR_NUMBER don’t work outside of forks it seems):

Check if it is a pull request:


Get PR number:



Glad that you solved this. We actually suggest using

if [[ ! -z $CIRCLE_PULL_REQUEST ]] ; then <something> ; fi

but that should have the same effect.


these are only available for forked builds :frowning: I’ve opened a separate discussion to get a few ENV’s accessible to non-forked repo builds.