Quality Gate fails for PRs to master but passes for develop with identical code
ALM used: Azure DevOps
CI system used: Azure DevOps
Languages of the repository: Python
Steps to reproduce:
Create a feature branch from develop (e.g., empty-test)
Make minimal changes (change import, remove comment, remove blank line)
Open PR: empty-test → master
Result: Quality Gate FAILS with 3 Code Smells from old issues
Open PR: empty-test → develop
Result: Quality Gate PASSES with 0 New Issues
Error observed:
```
When opening Pull Requests to master branch, SonarQube reports old code smells
from files that were not modified in the PR (e.g., api/engines/feature_flag_engine.py).
Issues reported (created 9 months ago):
Cognitive Complexity: 20/15 (L54)
Expression will always be constant (L83)
Add “break” statement or remove “else” clause (L98)
However, when opening the SAME PR to develop branch, these issues do NOT appear.
IMPORTANT: Other PRs to master have been opened before and passed SonarQube
analysis successfully. However, when checking the branch analysis in SonarQube:
Branch Analysis Status:
Master branch: Last analysis 2 years ago (commit: 12ddfa8e) - Status: “Not computed”
Develop branch: Last analysis 23 hours ago (commit: 0f7f083b) - Status: “Failed”
(but due to Overall Code issues, not New Code)
This indicates that while PR analysis runs, the base branch (master) baseline is
severely outdated, causing SonarQube to incorrectly identify old code as “new” when
comparing PRs against master.
```
Is there something that I could do?
I ran the pipeline to compute the quality gate but it does not work
This behavior usually happens when the baseline analysis for the target branch (master) is outdated, which matches what you’re seeing in your branch analysis status. Since your master branch hasn’t had a full analysis in a long time, SonarQube ends up comparing your PR against an old snapshot, causing legacy issues to be flagged as new.
A recommended fix is to trigger a full analysis on the master branch so SonarQube can refresh the baseline. Once that’s done, PRs targeting master should correctly report only new issues. You may also want to double-check your project’s New Code definition settings to ensure consistency across branches.
If you’re managing distributed pipelines or working with multiple regional teams (including teams in south africa), keeping baseline scans consistent across branches becomes even more important for reliable results.
Thank you for the clarification. I’ve tried to run a full analysis on the master branch by manually triggering the Azure DevOps pipeline, but the branch baseline in SonarQube is still not updating.
Here’s what I’ve done:
Manually ran the pipeline on master branch
The “SonarCloud Analysis” stage completed successfully
All jobs passed: “Define Sonar Project Key”, “Creating a project in S…”, “Configuring Project…”, “Send Metrics to Archit…”
However, when I check the master branch in SonarQube UI, it still shows “Last analysis 2 years ago”
For comparison, the develop branch pipeline (which has identical stages) successfully updates the branch analysis in SonarQube to “23 hours ago”.
Questions:
How can I trigger a full branch analysis (not a PR analysis) to update the master branch baseline?
Is there a specific parameter or configuration needed in the Azure DevOps pipeline to ensure it updates the branch baseline instead of just analyzing PRs?
Is there a way to manually trigger a branch analysis directly from the SonarQube UI?
I cannot find any option in the SonarQube web interface to manually trigger a branch analysis. Could you please provide step-by-step instructions on how to properly update the master branch baseline?
This is to be expected. Your PR analysis reflects the changes in empty-test, so when compared to empty-test there are no new / additional issues.
I think Zarha explained this well.
Either you didn’t actually analyze the branch you think you did - did you manually specific sonar.branch.name=master? - or the back-end processing of the analysis report failed. Can you check project Administration → Background Tasks?