Skip to content
Latchkey

SonarScanner "sonar.pullrequest.key ... required for PR analysis" in CI

Pull request analysis needs the PR number, the source branch, and the target branch. Supplying one without the others makes the scanner reject the configuration, since all are required together.

What this error means

The scanner fails with a message that sonar.pullrequest.key (or sonar.pullrequest.branch / sonar.pullrequest.base) is set but the others are missing, so PR analysis cannot proceed.

sonar-scanner
ERROR: Both 'sonar.pullrequest.key' and 'sonar.pullrequest.branch' parameters are required
for a pull request analysis.

Common causes

Only some PR properties are provided

The workflow sets the PR key but not the source or base branch, so the scanner has an incomplete PR configuration.

Manual PR properties fight the auto-detection

The scan action can auto-detect PR context from the CI event; setting some properties by hand can leave the set inconsistent.

How to fix it

Provide all three PR parameters or none

  1. Either let the scan action auto-detect the pull request context on pull_request events.
  2. Or set all of key, branch, and base together when configuring manually.
  3. Re-run on a pull_request trigger.
.github/workflows/ci.yml
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
-Dsonar.pullrequest.branch=${{ github.head_ref }}
-Dsonar.pullrequest.base=${{ github.base_ref }}

Let the action detect PR context

On a pull_request trigger the SonarSource action reads the PR key and branches from the event, so you often need to set nothing.

How to prevent it

  • Trigger analysis on pull_request so PR context is detected.
  • When setting PR properties manually, always set all three.
  • Avoid mixing manual PR properties with auto-detection.

Frequently asked questions

What causes ""sonar.pullrequest.key ... required""?
The workflow sets the PR key but not the source or base branch, so the scanner has an incomplete PR configuration.
How do I fix "sonar.pullrequest.key ... required"?
Provide all three PR parameters or none

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card