Pull request analysis doesn't flag the same issues on the same code going to different branches

  • Azure DevOps git
  • Azure DevOps pipelines
  • YAML task SonarCloudAnalyze@2
  • C#

My Pull Request analysis of new code going into a long-lived branch (main) finds more issues than that same new code going into a short-lived branch

Long-Lived destination (main) - Sonar found a basic unused field

Short-Lived destination (teams/main-cts) - Sonar DID NOT find the issue

Might I have something misconfigured?

Hi,

Welcome to the community!

Could you share what you’re trying to accomplish here?

 
Thx,
Ann

Yes, of course, sorry it wasn’t clear.

I’d like Sonar to flag the issue in both cases so that me and my teammates can catch issues when they are going into our Team/Dev/QA environments before they go into UAT/Prod.

Our “git flow” looks like this loosely:

dev-work-item-123-branch —PR—> team-branch —PR—> main

We have Sonar setup to analyze all PRs and it would be nice if it would catch these issue in the first PR that goes from an individual developer into our Team branch instead of later after it has already been integrated into our Team environment and is about to go into main.

Hi,

Thanks for the context.

Let me ask: is your team branch truly short-lived? Do you kill it and start a new one on a regular basis? Because I’m suspecting something about what’s counted as “new” here, and an apples-to-apples comparison of both branches being long-lived would sure simplify things.

 
Ann

Hmm, you know, you are right. We don’t fully kill off the Team branch (regularly) we just continually add more and more commits to it, same as we do main, just main sits “above” it in the flow and gets deployed to Prod, where the Team branch would only ever get deployed to Team/Dev environment.

I’ll rename my Topic.

Another point that your “new” comment made me think of - the issue in C# code that Sonar identified was NOT “new” code. You can see the PR code viewer doesn’t highlight it in red (removed) or green (added). That “unused field” had existed in that same file in both branches for some time. We have other examples too of “missed issues” at the Team level, this was just an easy one to explain - or so I thought :slight_smile:

Thanks for your engagement so far Ann!

Ann - any other ideas or questions about my setup so that I may be able to get the same level of scanning on all the branches?

Hi,

My first suggestion is to analyze the team branch as a long-lived branch. Unfortunately, that means you’ll have to scrap it and start again since you can’t change a branch’s type.

Then we’ll have an apples-to-apples comparison to work with.

 
Ann