Facing issue while running PR analysis on SonarCloud from Azure DevOps pipeline

Hi, We have setup SonarCloud analysis from our azure devops yaml pipeline (using ubuntu MS hosted agent) using built-in tasks like Prepare, Analyze and Publish (Also tried with ant sonarcheck command still same error). While running manually from branch, the execution is successful & we’re able to see the data on the sonarcloud portal.
But when we raise a PR and the Automated PR run is triggered on the pipeline, it fails with below errors:

bin/platform/build.xml:72: The following error occurred while executing this line:
bin/platform/resources/ant/sonar.xml:95: java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore

Caused by: java.lang.IllegalStateException: Unable to load component interface org.sonar.scanner.scan.branch.BranchConfiguration

Caused by: Could not find the pullrequest with key ‘2553’
Caused by: org.sonarqube.ws.client.HttpException: Error 404 on https://sonarcloud.io/api/alm_integration/show_pullrequest?project=xxxx&pullrequestKey=xxx: {“errors”:[{“msg”:“Unable to find the pullrequest with key \xxx\xxx”}]}

While the manually triggered branch run is working fine,issue occurs only with the PR automated runs.
We have already setup PR from the admin settings of the project on the sonar cloud portal. We’re also using valid service connection setup on the Azure DevOps for Sonar Cloud.

Please help if anyone has any inputs.

Hey there.

Have you checked to see if the token set at the Organization level is still valid? (global Administration > Organization settings)

You can also check if you have something configured at the project-level: (Project-level Administration > Pull Requests > Integration with Azure DevOps Services > Personal access token).

Typically when main branch analysis works but PR analysis fails, this is the culprit.

Hey Colin,

Thanks for the response.

Yes I have tested the token which I used to configure on Azure DevOps service connection. It is working fine with connection established.
Even the valid PAT token I have added under Pull Requests of Project admin settings.
The project was created very long ago on the Sonar Cloud portal which we are trying to use now, could it be because of that ?

Does the Sonar Token need to have been created by an Admin or anyone with write access can create one ?

To be clear, this should be an Azure DevOps PAT, not a SonarCloud PAT. Have you added a PAT that you generated in Azure DevOps? This won’t be the same one as you’ve added in the Azure DevOps service connection (which should be a SonarCloud PAT).

Yes, In Azure DevOps service connection it would be SonarCloud PAT .
In Pull Requests under the SonarCloud project settings it would be Azure PAT.

I’ve sent you a private message for more details.

Thank you for the response.
I created another project manually on Sonar Cloud & used that in my azure pipeline. It ran successfully.

Okay! And that worked without setting any PAT at the project-level? In that case, try removing the PAT you have set at the project-level in the failing project.