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.
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
- Either let the scan action auto-detect the pull request context on pull_request events.
- Or set all of key, branch, and base together when configuring manually.
- Re-run on a pull_request trigger.
-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_requestso PR context is detected. - When setting PR properties manually, always set all three.
- Avoid mixing manual PR properties with auto-detection.