Azure Devops Pipeline failing when running from pull request

  • ALM used: Azure Devops
  • CI system used: Azure Devops
  • Sonarcloud Project: Private

When our developers run a pipeline to analyse code directly on the main branch → Succeeds without issues:

INFO: Load project pull requests
INFO: Load project pull requests (done) | time=84ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=5ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=81ms
INFO: Load active rules
INFO: Load active rules (done) | time=1988ms

However when running the same pipeline, settings, … from a pull request the following error happens:

INFO: Load project pull requests

INFO: Load project pull requests (done) | time=53ms

INFO: Load branch configuration

INFO: ------------------------------------------------------------------------

INFO: EXECUTION FAILURE

INFO: ------------------------------------------------------------------------

INFO: Total time: 28.999s

INFO: Final Memory: 20M/70M

INFO: ------------------------------------------------------------------------

##[error]ERROR: Error during SonarScanner execution

ERROR: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator

ERROR:

ERROR: Error during SonarScanner execution

ERROR: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator

ERROR:

##[error]The SonarScanner did not complete successfully

The SonarScanner did not complete successfully

##[error]15:31:21.466 Post-processing failed. Exit code: 1

15:31:21.466 Post-processing failed. Exit code: 1

##[error]The process '/usr/bin/dotnet' failed with exit code 1

Finishing: Run Code Analysis

We’ve tried setting a new token etc, which verifies without issues but can not seem to work out the issue.
Any suggestions? Our developers are stuck right now and can not work because of this.

Hey there.

Have you checked to see if you’ve set a token at the project-level as well? (Project-level Administration > Pull Requests > Integration with Azure DevOps Services > Personal access token).

SonarCloud will use what’s set at the project-level if something is set.

That was exactly the issue, thanks!

Happy to help.

I also recognize it is a very unhelpful (and wrong) error message.

We’ve had a few reports about this in the last months all with the same cause (invalid Azure DevOps token configured somewhere on SonarCloud).

I’ve drawn up a report of these and reported them to the right team internally – hopefully, we can make this less confusing soon.

Thanks again for reporting it!