SonarCloud Analyze - Project not found

  • Azure DevOps
- task: SonarCloudPrepare@1
  displayName: 'Prepare analysis configuration'
  inputs:
    SonarCloud: 'SonarCloud.io - <org>'
    organization: 'myorg'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: 'myorg_Product-MYPRODUDCT-Frontend'
    cliProjectName: 'Product-MYPRODUDCT-Frontend'
    cliSources: 'src'
    extraProperties: |
      # Additional properties that will be passed to the scanner, 
      # Put one key=value per line, example:
      # sonar.exclusions=**/*.bin
      sonar.sources=src
      sonar.test.inclusions=**/testing/**,**/*.spec.ts
      sonar.typescript.lcov.reportPaths=coverage/lcov.info
  • Typescript/Angular
Starting: sonarcloud.io - Analyze
==============================================================================
Task         : Run Code Analysis
Description  : Run scanner and upload the results to the SonarCloud server.
Version      : 1.30.0
Author       : sonarsource
Help         : Version: 1.30.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarscanner-for-azure-devops/)
==============================================================================
/adoonlineagent/1/_work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.30.0/sonar-scanner/bin/sonar-scanner
INFO: Scanner configuration file: /adoonlineagent/1/_work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.30.0/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.15 Private Build (64-bit)
INFO: Linux 5.4.0-120-generic amd64
INFO: User cache: /home/MYORG/.sonar/cache
INFO: Scanner configuration file: /adoonlineagent/1/_work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.30.0/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarCloud
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=157ms
INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
INFO: User cache: /home/MYORG/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=71ms
INFO: Load/download plugins (done) | time=291ms
INFO: Loaded core extensions: developer-scanner
INFO: Found an active CI vendor: 'Azure DevOps'
INFO: Load project settings for component key: 'MYORG_Product-MYPRODUCT-Frontend'
INFO: Load project settings for component key: 'MYORG_Product-MYPRODUCT-Frontend' (done) | time=26ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=1ms
INFO: Project key: MYORG_Product-MYPRODUCT-Frontend
INFO: Base dir: /adoonlineagent/1/_work/1/s
INFO: Working dir: /adoonlineagent/1/_work/1/s/.scannerwork
INFO: Load project branches
INFO: Load project branches (done) | time=59ms
INFO: Check ALM binding of project 'MYORG_Product-MYPRODUCT-Frontend'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'MYORG_Product-MYPRODUCT-Frontend' (done) | time=21ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=39ms
INFO: Load branch configuration
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 2.882s
INFO: Final Memory: 20M/80M
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]ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
##[error]The process '/adoonlineagent/1/_work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.30.0/sonar-scanner/bin/sonar-scanner' failed with exit code 2

We have tried generating a new Token in SonarCloud and using it on the Service Connection in Azure Devops - this did not help.
This taks has been working fine before.

Also, I seem to be able to analyze the master branch, but not a CI Build from a PR (they use the same build yaml though…?)

Hi,

I think the problem here is your input names. From the example project, it should be projectKey and projectName rather than cliProjectKey and cliProjectName.

 
HTH,
Ann

Hi, that is wrong. If you have scannerMode = ‘CLI’ then the key is cliProjectKey.
This is from the task.json:

 {
      "name": "cliProjectKey",
      "type": "string",
      "label": "Project Key",
      "required": true,
      "helpMarkDown": "The SonarQube project unique key, i.e. `sonar.projectKey`",
      "visibleRule": "scannerMode = CLI && configMode = manual"
    },
    {
      "name": "projectKey",
      "type": "string",
      "label": "Project Key",
      "required": true,
      "helpMarkDown": "The SonarQube project unique key, i.e. `sonar.projectKey`",
      "visibleRule": "scannerMode = MSBuild"
    },

Note the “visibleRule”.
Also, as I said, this has worked fine for months now…

To prove this, I have take screenshots from a freshly configured task in Azure DevOps:


image

As you can see, it generates the same config.

1 Like

I was able to “resolve” this. I’ve deleted the whole project and started it from scratch (same project key) - It now works with the exact same pipeline…

I really wish there were easily accessible server-side logs :frowning:

1 Like