Sonarcloud cannot find project when triggered by PR but works with manual triggers Azure devops

Brief overview:

  • ALM used: Azure Devops
  • CI system used: Azure DevOps
  • Scanner command used when applicable: NA
  • Languages of the repository: Python
  • Error observed (Only occurred when being triggered by pull requests):
##[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: Re-run SonarScanner using the -X switch to enable full debug logging.
  • Steps to reproduce:
    • Setup branch policy to trigger static analysis pipeline upon pull requests
    • Create a pull request to target branch

Detailed description:
Our pipeline suddenly encountered the mentioned error few days ago. No code or configuration was changed around the time of incident. We created the pipeline using yaml.
Here’s a snippet of our current pipeline, with removal of unrelated parts:

trigger: none

variables:
  system_accesstoken: $(System.AccessToken)

jobs:
- job: PipelineName
  pool: 
    vmImage: ubuntu-18.04
  variables:
    - group: sonar-variable-group
  steps:
  - task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
    displayName: 'Prepare analysis on SonarCloud'
    inputs:
      SonarCloud: 'sonarcloud_connection'
      organization: $(ORGANIZATION)
      scannerMode: CLI
      configMode: manual
      cliProjectKey: $(PROJECT_KEY)
      cliProjectName: $(PROJECT_NAME)
      extraProperties: |
        # Additional properties that will be passed to the scanner, 
        # Put one key=value per line, example:
        sonar.exclusions=**/*.bin,**/*.json,**/*.yaml
        sonar.python.coverage.reportPaths=modules/coverage.xml

  - task: SonarSource.sonarcloud.ce096e50-6155-4de8-8800-4221aaeed4a1.SonarCloudAnalyze@1
    displayName: 'Run Code Analysis'

  - task: SonarSource.sonarcloud.38b27399-a642-40af-bb7d-9971f69712e8.SonarCloudPublish@1
    displayName: 'Publish Quality Gate Result'

The main twist is that the pipeline still works if triggered manually. PR-triggered pipeline will encounter mentioned error above.
Does anyone have any idea what happened?

Hey there.

Can you widen the logs you’ve shared a bit to show at what point exactly in the analysis the failure occurs?

Based on some other reports, it’s possible the token being used to make the connection between SonarCloud and Azure DevOps is (no longer) valid.

Take a look at your project-level Administration > Pull Requests or organization-level Administration > Organization settings > Azure DevOps connectivity management and make sure a valid token is set.

HI Colin,
I checked the token and it’s indeed invalid. I changed the token and now everything is working again. The issue can now be considered resolved.
Thanks for the support. I really appreciate it.

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