SonarQube analysis only on changed method or changed lines in New Code

SonarQube analysis only on changed method or changed lines

Current Process:

  1. Analyzed complete code in master branch and make it as reference for feature branches
    
  2. SonarQube analysis done on changed lines in new code (based on reference branch)

Issue: Quality Gate failed due to analysis report on unchanged methods or unchanged lines.

Example:

  1. Test.cs file contains 5 methods containing some common data
  2. Developer changed in Method1-line1
  3. In first analysis sonar shows code smell in Method1-line1
  4. Developer fixes code smell in Method1-line1
  5. In second analysis report shows code smell or bugs in other Methods (which are unchanged)

please help me to configure the server based on requirements.

Thanks in advance.

Do you run the sonar scan on the changes in a feature branch before the merge into the main branch or run the scan on the main branch after they are merged?

Usually people do the former while it’s PR, but the message posted says the latter.

Thank you for your response

we are running analysis on feature branch code before merging.
PR will be merged to main branch after build success

Is the second analysis that you are looking at for the same PR/branch or is it from the main/master branch?

for step 4 did the developer push another commit to the same remote branch and trigger a re-run of the pipeline for that branch?

How have you defined “new code”?

Is the second analysis that you are looking at for the same PR/branch or is it from the main/master branch?
Ans: Yes, It is Same PR/Branch

for step 4 did the developer push another commit to the same remote branch and trigger a re-run of the pipeline for that branch?
Ans: Yes

How have you defined “new code”?

New Code is defined with reference branch.

Analyzed complete code in master branch and make it as reference for feature branches


![image|690x238](upload://i1LfRMR4uShDS0Dlp5SI92cUSGJ.png)