Start Free
9.9 | Analyzing source code | Pull request analysis

Was this page helpful?

Pull request analysis

On this page

Pull Request analysis is available starting in Developer Edition.

You can see your pull requests in SonarQube from the branches and pull requests dropdown menu of your project.

Pull request analysis shows your pull request's quality gate and analysis in the SonarQube interface. This analysis shows new issues introduced by the pull request before merging with the target branch:

View of a sample PR analysis with metrics

The new code should be your focus moving forward when using the Clean as You Code strategy. More about this can be found in the SonarQube user guide concepts pages.


Before analyzing your pull requests, make sure that:

  • The pull request source branch is checked out in the local repository.
  • The branch being targeted by the pull request is fetched and present in the local repository.
  • The analysis is being run on a local repository with valid repository metadata (e.g. the .git folders have not been removed). Avoid any attempt at previewing the merge or actions involving your main branch.
  • The code in the local repository matches the code in the remote repository (e.g once a PR is issued, no code is added to the local branch on the CI side before analysis).

Report pull request status to your DevOps Platform

You can also report the pull request analysis and quality gate status directly in your DevOps platform's interface. To set up pull request decoration, see the DevOps platform integration page that corresponds with your DevOps platform:

Pull request quality gate

quality gate lets you ensure you are meeting your organization's quality policy and that you can merge your pull request. The pull request uses your project quality gate as follows:

  • Focuses on new code: The pull request quality gate only uses your project's quality gate conditions that apply to new code metrics using the Clean as You Code strategy.
  • Assigns a status: Each pull request shows a quality gate status reflecting whether it passed or failed.

Pull request analyses on SonarQube are deleted automatically after 30 days with no analysis. This can be updated in Administration > Configuration > General Settings > Housekeeping > Number of days before purging inactive branches.

Analysis parameters

The following parameters enable Pull Request analysis.

Parameter NameDescription
sonar.pullrequest.keyUnique identifier of your Pull Request. Must correspond to the key of the Pull Request in your DevOps Platform.
e.g.: sonar.pullrequest.key=5
sonar.pullrequest.branchThe name of the branch that contains the changes to be merged.
e.g.: sonar.pullrequest.branch=feature/my-new-feature
sonar.pullrequest.baseThe branch into which the Pull Request will be merged.
Default: main branch
e.g.: sonar.pullrequest.base=main

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARLINT, SONARQUBE, SONARCLOUD, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License