Issues with sonarqube analyze and publish on ADO, depending on if PR or straight build

I am using Azure Devops (ADO), with github hosting the repos.

again: GitHub hosts the repos. ADO is the pipelines.

I had everything working when it was building on the main branch (No PRs).

The global PAT is valid, active for another year. I added a service connection a week ago, good for another year, it’s verified (at least via ADO).

Everything builds and unit tests successfully.

The pipeline portion looks like


* task: SonarCloudAnalyze@4
  displayName: ‘performing SonarQube analysis’
  inputs:
  jdkversion: ‘JAVA_HOME_17_X64’

- task: SonarCloudPublish@4
  displayName: 'publishing sonarqube results to sonarcloud.io'
  inputs:
    pollingTimeoutSec: '300'

However, when setting to a branch (I"m Marc, so I created a marc-dev branch that is PR’ing into a dev branch (which is an integration branch).

PRs automatically are triggered to build/scan, which it does.

However, it fails on finding a PR with key.
ERROR: Could not find the pullrequest with key ‘4’
The scanner engine did not complete successfully
Post-processing failed. Exit code: 1

I’ve googled around. nothing seems obvious. SO I thought, why not just build on that branch I’m PRing.

So I manually fired the build off using the marc-dev branch. IT actually scanned successfully! but puked on publishing the results.

##[error][ERROR] SonarQube Cloud: Error retrieving analysis: API GET '/api/qualitygates/project_status' failed. Axios Error message: Request failed with status code 403.
##[error][ERROR] SonarQube Cloud: Error while executing task Publish: Could not fetch analysis for ID '<my id>'
##[error]Could not fetch analysis for ID '<my id>'
##[section]Finishing: publishing sonarqube results to sonarcloud.io

needless to say, it didn’t actually publish the results to sonarqube. says my default branch hasn’t yet been analyzed.

ok, so let me build on the main branch (which hasn’t changed at all).
Yep. it worked the entire way, built, scanned and published.

trying the marc-dev branch now, straight build (no PR)
Nope. still errors out on that id. I don’t know what that id even is, it’s not any git commits. I did a git log > logs.txt and searched for myid, nothing. I see the latest commit on that branch, not that id.

but the fact that main worked proves that the global token works, and that the service connection works.

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

I went and downloaded the logs for the PR run. For that preparing sonar scan, it did seem to find the PR information itself, just seems to have lost it on the run itself.

Mind you: this is for a repo hosted in github, but devops pipelines in ADO (don’t ask, I didn’t design it!)

 ##\[section\]Starting: preparing SonarQube
================================================================
Task         : Prepare Analysis Configuration
Description  : Prepare SonarQube Cloud analysis configuration
 Version      : 4.1.0
Author       : sonarsource
Help         : [More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/)
==============================================================
\[INFO\]  SonarQube Cloud: Server version: 8.0.0.82941
\[command\]D:\\a_tasks\\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\\4.1.0\\classic-sonar-scanner-msbuild\\SonarScanner.MSBuild.exe begin /k:<ado org>\_<ado project>/o:<ado org>
SonarScanner for .NET 11.1
Using the .NET Framework version of the Scanner for .NET
Pre-processing started.
Preparing working directories…
Updating build integration targets…
Using SonarCloud.

 The JRE provisioning is a time consuming operation.
JRE provisioned: OpenJDK21U-jre_x64_windows_hotspot_21.0.9_10.zip.
 If you already have a compatible Java version installed, please add either the parameter “/d:sonar.scanner.skipJreProvisioning=true” or “/d:sonar.scanner.javaExePath=”.
 Fetching analysis configuration settings…
 Provisioning analyzer assemblies for cs…
 Installing required Roslyn analyzers…
Processing plugin: architecturecsharpfrontend version 2.22.0.8999
 Processing plugin: securitycsharpfrontend version 11.22.0.44751
Processing plugin: csharpenterprise version 10.20.0.135146
 Provisioning analyzer assemblies for vbnet…
Installing required Roslyn analyzers…
Processing plugin: securityvbnetfrontend version 11.22.0.44751
Processing plugin: vbnetenterprise version 10.20.0.135146
 Downloading cache. Project key: <ado org>\_<ado proj>, branch: dev.
Incremental PR analysis: 10 files out of 19 are unchanged.

Not sure why it says branch: dev unless it meant I was doing a PR into dev, which is true. the branch being PR’d is marc-dev.

Hi,

Welcome to the community and thanks for this thorough report!

As you say, you’ve checked the global PAT.

Ahem, speaking of… It’s possible to also set a PAT at the project level, and this is only used during PR analysis. Can you check that one too, please?

 
Thx,
Ann

Let me see. i know i haven’t done that.