SonarQube Scanner failing in master in docker run

We are trying to run Code coverage for PR Branch and master in a Ruby project using docker run, we are successful in running in PR branch but master failing will the following error

Parameter ‘sonar.pullrequest.key’ is mandatory for a pull request analysis

Please let me know how we can run both PR and master code coverage at the same time.

This is how we are running ./build/sonar-cloud

docker run \

 -e CHANGE_ID=${CHANGE_ID} \

 -e BRANCH_NAME=${BRANCH_NAME} \

 -e PROJECT_VERSION=$(git rev-parse --short=7 HEAD) \

 -e SONAR_TOKEN=${SONAR_TOKEN} \

 -e SONAR_PROJECT_BASE_DIR="/home/app" \

 --user="$(id -u):$(id -g)" \

 -v "$(pwd):/home/app" \

 sonarsource/sonar-scanner-cli

 
**Sonar-project.properties**

sonar.organization=liveramp

sonar.projectKey=LiveRamp_company_admin

sonar.projectVersion=${env.PROJECT_VERSION}

sonar.sources=app,config,lib,bin,build,Gemfile,Rakefile,config.ru

sonar.tests=spec,test

sonar.host.url=[https://sonarcloud.io](https://sonarcloud.io/)



# Custom report paths

sonar.ruby.coverage.reportPaths=coverage/.resultset.json

sonar.ruby.rubocop.reportPaths=rubocop_report.json



# Pull Request information

sonar.pullrequest.key=${env.CHANGE_ID}

sonar.pullrequest.branch=${env.BRANCH_NAME}

sonar.pullrequest.base=master

sonar.pullrequest.github.repository=LiveRamp/company_admin



**Jenkins Log**

+ ./build/sonar-cloud

Unable to find image 'sonarsource/sonar-scanner-cli:latest' locally

latest: Pulling from sonarsource/sonar-scanner-cli

804555ee0376: Pulling fs layer

3c9135236624: Pulling fs layer

3c98ba2e08d9: Pulling fs layer

58d36242bf10: Pulling fs layer

492b4d196001: Pulling fs layer

58d36242bf10: Waiting

3c98ba2e08d9: Verifying Checksum

3c98ba2e08d9: Download complete

804555ee0376: Verifying Checksum

804555ee0376: Download complete

492b4d196001: Verifying Checksum

492b4d196001: Download complete

58d36242bf10: Verifying Checksum

58d36242bf10: Download complete

3c9135236624: Verifying Checksum

3c9135236624: Download complete

804555ee0376: Pull complete

3c9135236624: Pull complete

3c98ba2e08d9: Pull complete

58d36242bf10: Pull complete

492b4d196001: Pull complete

Digest: sha256:d57263c689fd3131730916642cd76595e78a174342e72e6a43a340efed49088f

Status: Downloaded newer image for sonarsource/sonar-scanner-cli:latest

INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties

INFO: Project root configuration file: /home/app/sonar-project.properties

INFO: SonarQube Scanner 4.2.0.1873

INFO: Java 11.0.3 AdoptOpenJDK (64-bit)

INFO: Linux 4.15.0-1050-gcp amd64

INFO: User cache: /home/app/.sonar/cache

INFO: SonarQube server 8.0.0

INFO: Default locale: "en_US", source code encoding: "US-ASCII" (analysis is platform dependent)

INFO: Load global settings

INFO: Load global settings (done) | time=745ms

INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu

INFO: User cache: /home/app/.sonar/cache

INFO: Load/download plugins

INFO: Load plugins index

INFO: Load plugins index (done) | time=173ms

INFO: Load/download plugins (done) | time=26147ms

INFO: Loaded core extensions: developer-scanner

INFO: Process project properties

INFO: Execute project builders

INFO: Execute project builders (done) | time=4ms

INFO: Project key: LiveRamp_company_admin

INFO: Base dir: /home/app

INFO: Working dir: /home/app/.scannerwork

INFO: Load project settings for component key: 'LiveRamp_company_admin'

INFO: Load project settings for component key: 'LiveRamp_company_admin' (done) | time=186ms

INFO: Load project branches

INFO: Load project branches (done) | time=129ms

INFO: Load projects for organization 'liveramp'

INFO: Load projects for organization 'liveramp' (done) | time=20993ms

INFO: Load project pull requests

INFO: Load project pull requests (done) | time=130ms

INFO: Load branch configuration

INFO: ------------------------------------------------------------------------

INFO: EXECUTION FAILURE

INFO: ------------------------------------------------------------------------

INFO: Total time: 53.535s

INFO: Final Memory: 6M/27M

INFO: ------------------------------------------------------------------------

ERROR: Error during SonarQube Scanner execution

ERROR: Parameter 'sonar.pullrequest.key' is mandatory for a pull request analysis

ERROR: 

ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.

Hello @monsam, welcome to the community forum!

When starting an analysis we check if there are any PR related properties, and if there are we start a PR analysis. In your case it seems those PR related properties like sonar.pullrequest.key, sonar.pullrequest.branch or sonar.pullrequest.base are still present when running regular branch analysis on master (eventhough the value is probably empty).

If you do not set those properties when running branch analysis everything should work as expected.

Hope that helps,
Tom