# SonarQube scans files that have not changed in the Azure DevOps Pull Request (new code = Ref branch)

**URL:** <https://community.sonarsource.com/t/sonarqube-scans-files-that-have-not-changed-in-the-azure-devops-pull-request-new-code-ref-branch/136700>\
**Category:** SonarQube Server / Community Build\
**Tags:** coverage\
**Created:** [March 12, 2025, 4:43pm UTC](https://community.sonarsource.com/t/sonarqube-scans-files-that-have-not-changed-in-the-azure-devops-pull-request-new-code-ref-branch/136700 "2025-03-12T16:43:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rachkoud](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/rachkoud/32/67688_2.png) [@rachkoud](https://community.sonarsource.com/u/rachkoud)\
**Post date:** [March 12, 2025, 4:43pm UTC](https://community.sonarsource.com/t/sonarqube-scans-files-that-have-not-changed-in-the-azure-devops-pull-request-new-code-ref-branch/136700/1 "2025-03-12T16:43:24Z")

</div>

Hi,

We’re using SonarQube Server v2025.1 (102418) with Azure DevOps and the latest Azure Extension 7.1.1.

New code is defined as Reference branch (master), so we want to analyze only the files that have changed between the branch and master.

When **we modify only one file** in a Pull Request, SonarQube correctly scans that file and add comments for the issues in it :

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/1/a/1a66b164e7555a4137ee021d03a8ef3497510bda.png)

But in the Pull Request in the bottom, we have 8 comments and we have this error message for the files that are not par of the PR :

**This file no longer exists in the latest pull request changes. It may have been moved or deleted. View the comment in its original context.**

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/2/5/252617247c671b42ae0f393a9dea4fb302e2c092.png)

We don’t understand why it scans this file as it has not changed in the branch and the Pull Request?

We took one issue on a file that has not changed and open this file from the PR in SonarQube Code for this PR, we can see here that file is detected as new code. Then we open the same file from master and we compared the two version, **they are identitical!!**. We did the same with the file that has changed in the PR and we can see the changes!!

Same file but detected as new code :

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/9/d/9dd774fe5ce59ebd51d29ccea401566852fcfeb3.png)

This is our Azure pipeline :

```yaml
parameters:
- name: 'NugetVersion'
  type: string
- name: 'SolutionName'
  type: string
- name: 'SonarProjectKey'
  default: ''
  type: string
- name: 'SonarExclusion'
  default: ''
  type: string

steps:
- task: NuGetToolInstaller@1
  displayName: 'Use NuGet ${{ parameters.NugetVersion }}'
  inputs:
    versionSpec: ${{ parameters.NugetVersion }}
- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    feedsToUse: config
    nugetConfigPath: ./nuget.config
    externalFeedCredentials: 'Telerik Nuget Feed'
- task: SonarQubePrepare@7
  displayName: 'Sonar Prepare Analysis'
  inputs:
    SonarQube: 'SonarQube Gu'
    projectKey: ${{ parameters.SonarProjectKey }}
    projectVersion: '$(Nuget.Version)'
    extraProperties: |
     sonar.exclusions=${{ parameters.SonarExclusion }}
- task: VSBuild@1
  displayName: 'Build solution ${{ parameters.SolutionName }}'
  inputs:
    solution: '${{ parameters.SolutionName }}.sln'
    platform: 'any cpu'
    configuration: 'Release'
    maximumCpuCount: true
- task: DotNetCoreCLI@2
  displayName: 'Tests'
  inputs:
    command: test
    projects: '**/*Test*.csproj'
    arguments: '-c Release --logger trx --no-build --collect "Code Coverage"'
    publishTestResults: true
- task: SonarQubeAnalyze@7
  displayName: 'Sonar Code Analysis'
- task: SonarQubePublish@7
  displayName: 'Sonar Quality Gate Result'

```

Is it a bug? What is wrong with our configuration?

Thanks for support

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 13, 2025, 1:28pm UTC](https://community.sonarsource.com/t/sonarqube-scans-files-that-have-not-changed-in-the-azure-devops-pull-request-new-code-ref-branch/136700/2 "2025-03-13T13:28:01Z")

</div>

Hi,

Welcome to the community!

Detection of new code relies on SCM metadata, so I believe this is about the SCM metadata that’s available in your environment for analysis to read.

Can you make sure [the prerequisites](https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/pull-request-analysis/setting-up-the-pull-request-analysis/) are in place?

> [@rachkoud](#):
>
> New code is defined as Reference branch (master), so we want to analyze only the files that have changed between the branch and master.
> 
> When **we modify only one file** in a Pull Request,

It’s important to distinguish how PR analysis works versus the use of a reference branch.

When you define a reference branch, it’s in the context of the branch it’s being defined on. E.G. `main` is the reference branch for `develop`.

But PR analysis will “reference” the branch the PR targets, regardless of any reference branch settings in SonarQube.

&nbsp;  
HTH,  
Ann

---

<div class="post-metadata">

**Author:** ![rachkoud](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/rachkoud/32/67688_2.png) [@rachkoud](https://community.sonarsource.com/u/rachkoud)\
**Post date:** [March 14, 2025, 9:21am UTC](https://community.sonarsource.com/t/sonarqube-scans-files-that-have-not-changed-in-the-azure-devops-pull-request-new-code-ref-branch/136700/3 "2025-03-14T09:21:33Z")

</div>

Hi,

Thank you for the clarification but we followed the exact steps as your [Azure DevOps Integration | Mapping your organization with SonarQube](https://www.youtube.com/watch?v=oYvMmN6G3F0)

I can’t understand why it keeps scanning files outside of files changed in the Pull Request and also why we get this error message?

**his file no longer exists in the latest pull request changes. It may have been moved or deleted. View the comment in its original context.**

We tried many ideas to solve this issue but can’t understand why it keep scanning files outside of the PR.

We have the latest version of Sonar Server and Azure DevOps Extension.

Thanks for support

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 14, 2025, 1:30pm UTC](https://community.sonarsource.com/t/sonarqube-scans-files-that-have-not-changed-in-the-azure-devops-pull-request-new-code-ref-branch/136700/4 "2025-03-14T13:30:18Z")

</div>

Hi,

This isn’t about your integration configuration. It’s about your checkout.

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![rachkoud](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/rachkoud/32/67688_2.png) [@rachkoud](https://community.sonarsource.com/u/rachkoud)\
**Post date:** [April 14, 2025, 9:56am UTC](https://community.sonarsource.com/t/sonarqube-scans-files-that-have-not-changed-in-the-azure-devops-pull-request-new-code-ref-branch/136700/5 "2025-04-14T09:56:46Z")

</div>

Finally, we found out what was the problem, we clean up manually the Azure DevOps Agent source code, use this variable to find out where it is located :

[Use predefined variables](https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml)

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/3/b/3b4c4e95e23edbc6ba6b548f9d8f161d909cb299.png)

We used in our pipeline a clean step at beginning and were thinking that should be ok :

[Clean the local repo on the agent](https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/pipeline-options-for-git?view=azure-devops&tabs=yaml#clean-the-local-repo-on-the-agent)

steps:

- checkout: self  
persistCredentials: true  
clean: true

But for whatever reason the source code was not clean and that was the problem. Since then, we do not have any problem!

Thanks for support!
