Sonarcloud scanner not authorized with azure devops gradle plugin

  • ALM used => Azure DevOps

  • CI system used => Azure DevOps

  • Scanner command used when applicable => gradle plugin

  • Languages => Java

  • Error observed
    Execution failed for task :sonarqube You're not authorized to run analysis. Please contact the project administrator.

  • Steps to reproduce
    I’m using the sonarcloud prepare task before the gradle task but somehow I’m not authorized to scan the code. I double checked the service connection which is set to be used for all pipelines
    I’m also using a hosted agent

thanks for your help

Kind regards,

Hey there.

Have you already created this project on SonarCloud and used the project key (sonar.projectKey) that is provided in the UI tutorial?

Typically this error appears at the end of analysis when a user has Execute Analysis permissions but not Create Projects permission and a matching project key does not exist.

Hi Colin,

thanks for your quick reply, yes the project is already created in SonarCloud and the project key used in the prepare analysis is correct

Kind regards

  • I would recommend sharing screenshots of your Pipeline configuration as well as your SonarCloud project (where the key is shown in the URL of the project or the project Administration > Update Key)
  • Double-check there is no build.gradle file overriding the sonar.projectKey

my pipeline is the following
There is a build gradle file but nothing that is referring to sonar in it
I don’t have access to the admin section of sonar but I will check with the right person and let you know


  vmImage: ubuntu-latest 

workspace:

  clean: all

steps:

- task: SonarCloudPrepare@1

  inputs:

    SonarCloud: SonarCloud

    organization: myorg

    scannerMode: Other

    projectKey: 'KeyIsCorrect'

    projectName: 'KeyIsCorrect'

- task: Gradle@3

  inputs:

    workingDirectory: ''

    gradleWrapperFile: 'gradlew'

    gradleOptions: '-Xmx3072m'

    javaHomeOption: 'JDKVersion'

    jdkVersionOption: '1.11'

    jdkArchitectureOption: 'x64'

    tasks: 'build'

    #tasks: 'assembleRelease'

    sonarQubeRunAnalysis: true

    sonarQubeGradlePluginVersion: 2.6.1

   

- task: SonarCloudPublish@1

  inputs:

    pollingTimeoutSec: '300'

Hi Collin,

I don’t know if you can read what I’m posting.
Our projects are private and I do not whish to share in this forum details related to them.

if you cannot read this, let me know How I can share this info with you

Project Key: PE087_Msc.GoApp
Org: msc

Thanks for your help

Kind regards,

Hi Is there anything else that you need to help us ?

this is getting critical for our business

thanks for your help

Kind regards,

Hey there.

When the Other scanner mode is selected, the projectKey and projectName inputs should disappear as well, and the project key placed under Additional Properties (as described in the tutorial).

(I recognize this tutorial is then completely wrong in telling you to use the Run Code Analysis step and I’ll report this internally. The rest of your YAML looks fine, although you may want to bump the version of the sonarQubeGradlePluginVersion to the latest, 3.3)

Can you give this a try?

Hi Collin,
thanks for your reply.
I updated the pipeline as follows :

trigger:
- master

pool:
  vmImage: ubuntu-latest 

workspace:
  clean: all

steps:
- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'SonarCloud'
    organization: myorg
    scannerMode: 'Other'
    extraProperties: |
      sonar.projectKey='KeyIsCorrect'
      sonar.projectName='KeyIsCorrect'

- task: Gradle@3
  inputs:
    workingDirectory: ''
    gradleWrapperFile: 'gradlew'
    gradleOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.11'
    jdkArchitectureOption: 'x64'
    tasks: 'build'
    sonarQubeRunAnalysis: true
    sonarQubeGradlePluginVersion: '3.3'
    
- task: SonarCloudPublish@1
  inputs:
    pollingTimeoutSec: '300'

Unfortunately, I still have the same error :

Execution failed for task ‘:sonarqube’.
You’re not authorized to run analysis. Please contact the project administrator

thanks for your help

Kind regards

Just to add some detail, the error is happening within the gradle task execution
sonarcloud prepare executes always fine

Kind regards

Hey Mark.

  • I would still double-check your build.gradle file to make sure there are no overriding settings
  • You might try creating a new service connection in Azure DevOps using a token generated by a user who for sure has Execute Analysis permissions and Create Projects permissions in your organization to see if it makes a difference. I would also suggest verifying this token works by testing it manually (analyzing a project from your local machine).

Hey Collin,

sure no problem, this is the apps buld.gradle file :

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "confidential"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        abortOnError false
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.android.material:material:1.0.0'
    implementation platform('com.google.firebase:firebase-bom:26.8.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation platform('com.google.firebase:firebase-bom:26.3.0')
    implementation 'com.google.firebase:firebase-auth'
    implementation platform('com.google.firebase:firebase-bom:26.6.0')
    implementation 'com.google.firebase:firebase-database'
    implementation 'com.github.d-max:spots-dialog:1.1@aar'
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.firebase:geofire-android:2.2.0'
    implementation 'com.google.android.libraries.places:places:1.1.0'
    implementation 'com.google.maps.android:android-maps-utils:0.5'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-scalars:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.google.firebase:firebase-storage:19.1.1'
    implementation 'id.zelory:compressor:2.1.0'
    implementation 'com.airbnb.android:lottie:3.6.1'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.hbb20:ccp:2.4.0'
    implementation 'com.firebaseui:firebase-ui-database:6.2.0'
    implementation 'com.github.florent37:shapeofview:1.3.2'
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

apply plugin: 'com.google.gms.google-services'

let me know if you see something strange
in the meantime I will test the token option and will let you know ASAP

thanks again

Kind regards,

Hi Collin,

we have finally resolved this isse => we removed the quotes between the project name

thanks again for your support

Kind regards,

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