Error: Parameter 'sonar.pullrequest.branch' is mandatory for a pull request analysis


I created a basic test project on SonarCloud with Circle CI. Following the tutorial on the documentation, it worked perfectly, both on scanning the default branch and any PR.

Now I am trying to do the same thing in a “real” project, but this time I have this error.

ERROR: Error during SonarQube Scanner execution
ERROR: Parameter ‘sonar.pullrequest.branch’ is mandatory for a pull request analysis

Below is the content of my circle CI conf file:

      - image: circleci/php:7.3.9-fpm
      - checkout
      - sonarcloud/scan

  sonarcloud: sonarsource/sonarcloud@1.0.1

Does someone have ever faced this issue. What could be the element(s) that could cause this issue?


Hi @enrico69, welcome to the community forum!

Would it be possible to share the full output of the CircleCI build here of via a personal message?


@TomVanBraband Thank you :slight_smile:

Below is the output of the sonar job (let me know if you need anything more). You can notice it fails just after the configuration of the branch. I am a little bit lost since, on my test project, it goes through the whole process without any issue. The only difference is that, for both Github and Sonarcloud, we use a plan, since it is for a company.

#!/bin/bash -eo pipefail
set -e

if [[ ! -x "$SCANNER_DIRECTORY/sonar-scanner-$VERSION-$OS/bin/sonar-scanner" ]]; then
  curl -Ol$VERSION-$
  unzip -qq -o sonar-scanner-cli-$VERSION-$ -d $SCANNER_DIRECTORY

chmod +x $SCANNER_DIRECTORY/sonar-scanner-$VERSION-$OS/bin/sonar-scanner
chmod +x $SCANNER_DIRECTORY/sonar-scanner-$VERSION-$OS/jre/bin/java

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

100 40.4M  100 40.4M    0     0  11.0M      0  0:00:03  0:00:03 --:--:-- 11.0M
INFO: Scanner configuration file: /tmp/cache/scanner/sonar-scanner-
INFO: Project root configuration file: /home/circleci/project/
INFO: SonarQube Scanner
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 4.15.0-1052-aws amd64
INFO: User cache: /tmp/cache/scanner/.sonar/cache
INFO: SonarQube server 8.0.0
INFO: Default locale: "en", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=613ms
INFO: Server id: 74E9293
INFO: User cache: /tmp/cache/scanner/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=133ms
INFO: Load/download plugins (done) | time=20884ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=6ms
INFO: Project key: myrepo_myproject
INFO: Base dir: /home/circleci/project
INFO: Working dir: /home/circleci/project/.scannerwork
INFO: Load project settings for component key: 'myrepo_myproject'
INFO: Load project settings for component key: 'myrepo_myproject' (done) | time=138ms
INFO: Found an active CI vendor: 'CircleCI'
INFO: Load project branches
INFO: Load project branches (done) | time=129ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=124ms
INFO: Load branch configuration
INFO: Auto-configuring pull request 8359
INFO: ------------------------------------------------------------------------
INFO: ------------------------------------------------------------------------
INFO: Total time: 25.673s
INFO: Final Memory: 7M/200M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Parameter 'sonar.pullrequest.branch' is mandatory for a pull request analysis
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
Exited with code 2

Thank you,

Is it possible that you did not import this project through GitHub, and that you did do that with the test project? A Github API is called to determine the branch of the PR, but that can only be done when SonarCloud knows the location of the repository on GitHub side.

You can easily check if this is the case by going to your project page on SonarCloud, you should see a Github icon next to the project name if it is linked to Github.


Yes I see the GitHub icon next to the project name. The integration should be good because before trying to integrate Sonar into our Circle CI, I tested the “Autoscan” beta feature and it worked well.

Just to be sure I also went to the Pull Request menu on Sonar, and set the Provider to Github and the repo identifier, though I did not have to do that in my test project.

Did you set the sonar.organization property in your file?

1 Like

Exactly! In the meantime I found this issue. I was totally mistaken by the error message. Stupid error as expected. Thanks!

1 Like

so what was the issue? the missing sonar.organization?

I came here via google search cause I have same issue but I have sonar.organiszation property set. the issue happens in a PR scan. The PR is comming from a fork repository.

Here is the CircleCI build -->

Yes it was missing configuration on the sonar project configuration file.
However, regarding your stacktrace, it reminds me that sometimes, for PR, I had to add that in my circle ci file:

              command: |
                  if [[ -z ${CIRCLE_PULL_REQUEST} ]]; then \
                      sonar-scanner; \
                  else \
                      sonar-scanner -Dsonar.pullrequest.key=${CIRCLE_PULL_REQUEST##*/} -Dsonar.pullrequest.branch=${CIRCLE_BRANCH}; \
1 Like

thanks for coming back. I’ll try that. I was not aware that when using CircleCI Orb by SonarCloud I can also use the sonar-scanner directly.

oh, I guess that does not work with the Orb, right?

I get this error:

/bin/bash: line 3: sonar-scanner: command not found

Right. We use an image:

  • image: sonarsource/sonar-scanner-cli:4.3
1 Like

@ecourtial do you have a public example on Github?

Yes. Actually I have a simple example, without using the docker image :

1 Like