SonarQube server does not recognize target branch in Pull Request in Azure Pipelines

Hello!
I’m using the SonarQube Community Edition (version 24.12.0.100206) integrated with Azure Pipelines. I configured my azure-pipelines.yml to perform SonarQube analysis on pull requests. However, every time I try to run a scan, SonarQube analyzes only the pull request branch and returns the following warning in the logs:
“WARN: Could not find ref ‘refs/heads/release/90’ in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin”.

I also tried running some Git commands in the pipeline to ensure SonarQube can access the pull request’s target branch, but it didn’t work. Also i’m using the Sonar Community branch Plugin to run analysis on another branchs.

Hi,

Welcome to the community!

This is about the prerequisites.

 
HTH,
Ann

Hi, Thanks for the answer!

I also have to implemente this step before the sonarAnalyse step:

  - script: |
      git remote set-url origin $(Build.Repository.Uri)
      git fetch origin $(System.PullRequest.TargetBranch):refs/remotes/origin/$(System.PullRequest.TargetBranch)
    displayName: 'Fetch PR Target Branch'
    condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))

This block ensures that the PR’s target branch is available locally in the build agent’s Git repository, allowing code comparison between branches - for example, for correct calculation of incremental test coverage or differential code analysis.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.