Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties

Project scans were working fine for over thirty days. Nothing has changed in source, sonarcloud settings or azure-pipeline yml. All of a sudden the project cannot be found. The Azure Personal Access Token has not expired.

Error Log:
INFO: Load project branches
INFO: Load project branches (done) | time=162ms
INFO: Check ALM binding of project 'macro-pfa_pfa'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'macro-pfa_pfa' (done) | time=109ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=173ms
INFO: Load branch configuration
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 35.419s
INFO: Final Memory: 20M/67M
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: Re-run SonarScanner using the -X switch to enable full debug logging.
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.
##[error]The process '/home/vsts/work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.31.1/sonar-scanner/bin/sonar-scanner' failed with exit code 2
Finishing: SonarCloud Run Code Analysis

azure-pipelines.yml:

variables:
  # Agent VM image name
  vmImageName: 'ubuntu-18.04'
  npm_config_cache: $(Pipeline.Workspace)/.npm

trigger:
  batch: true
  branches:
    include:
      - master
      - develop
      - releases/*
      - preview-space

jobs:
  - job: build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
      - template: templates/npm-steps.yml
      - task: Npm@1
        displayName: Prune
        inputs:
          command: custom
          customCommand: run prune
      - task: SonarCloudPrepare@1
        displayName: SonarCloud Prepare
        inputs:
          SonarCloud: 'macro-sonar-connection'
          organization: 'macro-pfa-org-key'
          scannerMode: 'CLI'
          configMode: 'manual'
          cliProjectKey: 'macro-pfa_pfa'
          cliProjectName: 'pfa'
      - task: Npm@1
        displayName: Create Cloudfoundry Build
        inputs:
          command: custom
          customCommand: run cf:build
      - task: SonarCloudAnalyze@1
        displayName: 'SonarCloud Run Code Analysis'
      - task: SonarCloudPublish@1
        displayName: 'SonarCloud Publish Quality Gate Result'
      - task: ArchiveFiles@2
        inputs:
          rootFolderOrFile: ./dist/
          archiveFile: '$(Build.ArtifactStagingDirectory)/packages.zip'
      - publish: $(Build.ArtifactStagingDirectory)/packages.zip
        artifact: drop

  - job: unit_tests
    displayName: Unit Tests
    pool:
      vmImage: $(vmImageName)
    steps:
      - template: templates/npm-steps-nobuild.yml
      # - task: Npm@1
      #   condition: or(
      #       eq(variables['Build.SourceBranch'], 'refs/heads/develop'),
      #       startsWith(variables['Build.SourceBranch'], 'refs/heads/releases')
      #     )
      #   displayName: Prepare for Audit
      #   inputs:
      #     command: custom
      #     customCommand: run audit:prep
      # - task: Npm@1
      #   displayName: Run Audit
      #   condition: or(
      #       eq(variables['Build.SourceBranch'], 'refs/heads/develop'),
      #       startsWith(variables['Build.SourceBranch'], 'refs/heads/releases')
      #     )
      #   inputs:
      #     command: custom
      #     customCommand: run audit
      - task: Npm@1
        displayName: Linting
        inputs:
          command: custom
          customCommand: run lint
      - task: Npm@1
        displayName: Run Unit Tests
        condition: succeededOrFailed()
        inputs:
          command: custom
          customCommand: run test
      - task: Npm@1
        displayName: Run Unit Tests With Coverage
        condition: succeededOrFailed()
        inputs:
          command: custom
          customCommand: run test:cov
      - template: templates/publish-test-report.yml
        parameters:
          package: bank-api
      - template: templates/publish-test-report.yml
        parameters:
          package: datamanager
      - template: templates/publish-test-report.yml
        parameters:
          package: bankfind-ui
      - template: templates/publish-test-report.yml
        parameters:
          package: common-modules

  - job: e2e_tests
    displayName: E2E Tests
    pool:
      vmImage: $(vmImageName)
    steps:
      - template: templates/npm-steps.yml
      - bash: |
          sudo sysctl -w vm.max_map_count=262144
          echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
        displayName: Increase Max Virtual Memory
      - task: Npm@1
        displayName: Start Docker
        inputs:
          command: custom
          customCommand: run docker-compose:up
      - template: templates/datamanager-e2e.yml
      - task: Npm@1
        displayName: Run Bank API E2E Tests
        condition: succeededOrFailed()
        inputs:
          command: custom
          customCommand: run test:ci:e2e
          workingDir: ./packages/bank-api
      - task: PublishTestResults@2
        displayName: Bank API - Publish E2E Test Results
        condition: succeededOrFailed()
        inputs:
          testResultsFiles: 'packages/bank-api/test-report-e2e.xml'
          testRunTitle: 'E2E Tests - Bank API'
      - task: Npm@1
        displayName: Run BankFind UI E2E Tests
        condition: succeededOrFailed()
        inputs:
          command: custom
          customCommand: run test:e2e
          workingDir: ./packages/bankfind-ui
      - task: PublishCucumberReport@1
        displayName: 'Publish CucumberReport'
        inputs:
          jsonDir: ./packages/bankfind-ui/features/
          outputPath: ./packages/bankfind-ui/features/
          theme: 'bootstrap'
          reportSuiteAsScenarios: true
          name: 'Regression Tests'
          title: BankFind UI - E2E
  - deployment: deploy
    displayName: Deploy
    dependsOn:
      - build
      - unit_tests
      - e2e_tests
    pool:
      vmImage: $(vmImageName)
    environment: 'fdic-nongfe-dev'
    condition: |
      and(
        succeeded(),
        or(
          eq(variables['Build.SourceBranch'], 'refs/heads/develop'),
          startsWith(variables['Build.SourceBranch'], 'refs/heads/releases'),
          eq(variables['Build.SourceBranch'], 'refs/heads/preview-space')
        )
      )
    strategy:
      runOnce:
        deploy:
          steps:
            - download: current
              artifact: drop
            - task: ExtractFiles@1
              inputs:
                archiveFilePatterns: '$(Pipeline.Workspace)/drop/packages.zip'
                destinationFolder: drop
                cleanDestinationFolder: true
            - bash: curl -L "https://packages.cloudfoundry.org/stable?release=linux64-binary&source=github" | tar -zx
              displayName: Install CF CLI
            - bash: ./cf api api.fr.cloud.gov
              displayName: Set CF API URL
            - bash: ./cf auth
              displayName: Authenticate CF CLI
              env:
                CF_PASSWORD: $(CF_PASSWORD)
                CF_USERNAME: $(CF_USERNAME)
            - bash: ./cf t -o fdic-nongfe -s pfa-dev
              displayName: CF Target Non-GFE
            - bash: ./cf push -f $(Build.SourcesDirectory)/drop/dist/manifest.yml --vars-file $(Build.SourcesDirectory)/drop/dist/environments/vars/nongfe.yml
              displayName: CF Push
            # - bash: ./cf terminate-task pfadatamanagerapi $(./cf tasks pfadatamanagerapi | grep -m 1 'work-manager' | cut -d' ' -f1)
            #   # gets the ID number of the most recent "work-manager" task
            #   displayName: Cancel any previous work-manager task
            #   continueOnError: true
            # - bash: ./cf run-task pfadatamanagerapi "npm run task:dist:work-manager" -m 2G --name work-manager
            #   displayName: Run all indexing tasks


sonar-project.properties
sonar.projectKey=macro-pfa_pfa

sonar.organization=macro-pfa-org-key

# This is the name and version displayed in the SonarCloud UI.

sonar.projectName=pfa

sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.

sonar.sources=.

# Encoding of the source code. Default is default system encoding

sonar.sourceEncoding=UTF-8

# identify branch as long living

# sonar.branch.name=develop

# sonar.branch.target=develop

Any update on this issue?

I’m also getting the same error.

We’ve checked the sonar properties file & sonar token, and both are properly configured/set. This might also be a permission issue as mentioned here [SOLVED]Project not found for a new project.
Unfortunately, I don’t have admin access to check permissions.

I am experiencing the same error but only while running checks for a pull request. Normal branches are running fine. It worked fine until last Monday. I had to regenerate the token in Azure and have saved the new one in SonarCloud under the pull request settings. First I thought it had something to do with that token, but since it was just regenerated I am certain the permissions stayed the same.

Very annoying since the error message is a general one. I have tried so many things that I have no clue what my next step could be. It just fails after Load branch configuration. I have not found any way to run the debug mode within the Azure pipelines for more information.

Did you manage to solve the issue on your end?

Just discovered that there is another place within SonarCloud that requires a valid Azure token. See this post as well: Sonarcloud analysis has started failing for azure devops with token invalid - #2 by Marcin_Majewski

Also there is a way to see the debug output within the SonarCloudPrepare task:

extraProperties: |
   sonar.verbose=true

In my case it showed a request to Azure failing with a 401 status which gave a clue. I updated the token within Sonarcloud > Profile picture (right top) > (Your organisation) > Administration > Organization settings. Scroll down to the Azure DevOps connectivity management section. There you can check whether the token is valid. A bit strange that the main branch kept working but the PR’s were failing.

1 Like

Hey, this might be relevant to future visitors:

If you were the one who generated the token, check (yourself or with an admin) whether you have the “Execute Analysis” permission on your SonarCloud user, and specifically for the project you are trying to run an analysis on. I had the same issue and managed to fix it by applying the permissions.

The only logic I see behind this misleading error is that, without the permissions, the project is “hidden” and deemed not found. The error should instead mention a lack of permissions…

Hope this helped!

2 Likes