SonarCloud: New organization Quality Gate not getting computed for main branch

I just on-boarded a new organization, imported the project, added SonarCloud tasks to the azure pipeline, yet the quality gate is still not getting computed for the main branch after days of pushing new commits, though the New Code definition is set to ‘Previous version’ right off the bat.

Usually after importing a project and re-running the analysis on the main branch a 2nd time the quality gate already gets computed. At least that’s how it worked with another organization i’ve onboarded a year ago.

I’ve pretty much used the same SonarCloudPrepare task configuration so I’m not sure what I’m doing wrong.

stages:
- stage: Build
  jobs:
  - job: Job1
    displayName: 'Build and publish output'
    steps:
      - task: SonarCloudPrepare@1
        inputs:
          SonarCloud: 'SonarCloud'
          organization: '***'
          scannerMode: 'CLI'
          configMode: 'manual'
          cliProjectKey: '***'
          cliProjectName: '***'
          cliSources: '$(build.sourcesDirectory)'

      - task: UseDotNet@2
        displayName: 'Install .NET 6.0 SDK'
        inputs:
          packageType: 'sdk'
          version: '6.0.x'
          includePreviewVersions: true
          performMultiLevelLookup: true

      - task: DotNetCoreCLI@2
        displayName: 'Restore packages'
        inputs:
          command: 'restore'
          projects: '***'
          restoreArguments: '--runtime linux-x64'
          feedsToUse: 'select'
          vstsFeed: ''***'

      - task: DotNetCoreCLI@2
        displayName: 'Build and publish output'
        inputs:
          command: 'publish'
          publishWebProjects: false
          projects: '***'
          arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(Build.BuildId)'
          modifyOutputPath: false

      - task: PublishBuildArtifacts@1
        displayName: 'Publish artifact'
        inputs:
          PathtoPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)'
          ArtifactName: 'drop'
          publishLocation: 'Container'
      
      - task: SonarCloudAnalyze@1

      - task: SonarCloudPublish@1
        inputs:
          pollingTimeoutSec: '300'

Hey there.

When a new organization is created, there’s no setting applied at all.

So I would guess that this configuration was set at the organization-level after your project was created.

You could test this with a new project – and for the existing project, set the New Code under project-level Administration

Hello! I set the New Code definition before importing the project.

Finally fixed the issue and here’s the step-by-step:

  1. Go to Organization > Administration > Project Management and restore access to the newly imported Project.

  2. Go to Project > Administration > New Code and set the New Code definition.

  3. Re-run the main branch build to trigger a new analysis.

FYI:
The Administration link on the project level didn’t appear for me until I did a ‘Restore Access’.