Not Authorized to run Analysis when using specific properties

Hello. I’m trying to implement certain properties during my sonar scan so I can allow the SonarQube plugin for Drone to work. I am running the scan using Maven to test why it is failing. Bottom line, if I remove certain properties I am able to run the scan successfully without getting the “You’re not authorized to run analysis” message, however I need these properties to work to get the Drone plugin to work.

I have tried with 2 different tokens from an admin user that has been granted all privileges going to Administration > Permissions. My own user is an Administrator and has been granted permissions on the project.

Failing command:

mvn sonar:sonar -X -Dsonar.projectKey=[redacted] -Dsonar.projectName=[redacted] -Dsonar.host.url=https://sonarcloud.io -Dsonar.branch=development -Dsonar.sources=src/main/java -Dsonar.java.libraries=./target/classes -Dsonar.java.binaries=./target/classes -Dsonar.login=[redacted]

The command executes successfully when removing the following properties: libraries, binaries, sources and branch.

Debug logs are too extensive to provide whole, so if there’s a section that will help please let me know and I will provide.

[INFO] 09:12:54.304 Analysis report generated in 43ms, dir size=247 KB
[INFO] 09:12:54.331 Analysis report compressed in 27ms, zip size=83 KB
[INFO] 09:12:54.331 Analysis report generated in /home/[redacted]@[redacted]11.local/Projects/git/[redacted]/target/sonar/scanner-report
[DEBUG] 09:12:54.332 Upload report
[DEBUG] 09:12:54.666 POST 403 https://sonarcloud.io/api/ce/submit?organization=[redacted]&projectKey=[redacted]_[redacted]&projectName=[redacted]_[redacted]&projectBranch=development | time=334ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  13.780 s
[INFO] Finished at: 2019-10-23T09:12:54-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project [redacted]: You're not authorized to run analysis. Please contact the project administrator. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project [redacted]: You're not authorized to run analysis. Please contact the project administrator.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: You're not authorized to run analysis. Please contact the project administrator.
    at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute (ScannerBootstrapper.java:67)
    at org.sonarsource.scanner.maven.SonarQubeMojo.execute (SonarQubeMojo.java:104)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.sonar.api.utils.MessageException: You're not authorized to run analysis. Please contact the project administrator.
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Hi Nate,

Sorry for the late response.
In the failing command that you posted I do not see a sonar.organization parameter, but then the failing request

POST 403 https://sonarcloud.io/api/ce/submit?organization=[redacted]&projectKey=[redacted]_[redacted]&projectName=[redacted]_[redacted]&projectBranch=development | time=334ms

does contain an organization parameter. Can you double check that the organization is correct?

If that is the case could you please share the debug logs of the command that works (so without libraries, binaries, sources and branch as you said). You do not have to share the whole log output, everything after the line [DEBUG] 09:12:54.332 Upload report is enough.

Thanks,
Tom

1 Like

Hi Tom,
Yes that seems to have been the issue, even though I had the organization in my pom.xml properties I still had to include the organization argument for this to succeed.

Thanks

Hello Tom, I’m facing a similar error but your solution doesn’t seem to apply to my problem. Any idea on this?

Link : SonarQube error: You're not authorized to run analysis, despite passing the token with build cmd