=> You're not authorized to run analysis. Please contact the project administrator

Template for a good new topic, formatted with Markdown:

  • ALM used: Bitbucket Cloud
  • CI system used: Shippable
  • Languages of the repository: Typescript
  • Only if the SonarCloud project is public, the URL: SonarCloud
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
  • Steps to reproduce: Everytime I build with CI, or run cmd from local
  • Potential workaround: Give “Anyone”, “Execute Analysis permission”

I am the administrator. I created a login key and I’m using it like below.

npm run sonar -Dsonar.login=XXXXXXXX -Dsonar.projectVersion=0.0.3 -Dsonar.pullrequest.branch=bugfix/issue-7-sonar-analysis -Dsonar.pullrequest.key=false -Dsonar.pullrequest.base= -Dsonar.issuesReport.console.enable=true -Dsonar.pullrequest.provider=bitbucketcloud -Dsonar.pullrequest.bitbucketcloud.repository=resume -Dsonar.pullrequest.bitbucketcloud.owner= -Dsonar.pullrequest.bitbucketcloud.triggerCommit=61987a70c993c24bf1421d3e924fc7aa98739aa4

and it fails.

> sonar-scanner

19:20:25.617 INFO: Load project repositories
19:20:26.206 DEBUG: GET 403 https://sonarcloud.io/batch/project.protobuf?key=com.yalimaytul%3Aresume | time=589ms
19:20:26.212 ERROR: Cannot analyze file src/app/footer/footer.component.html
java.lang.IllegalStateException: You’re not authorized to run analysis. Please contact the project administrator.
at org.sonar.scanner.scan.filesystem.MetadataGenerator.setMetadata(MetadataGenerator.java:55)
at org.sonar.scanner.scan.filesystem.FileIndexer.lambda$indexFile$0(FileIndexer.java:127)
at org.sonar.api.batch.fs.internal.DefaultInputFile.checkMetadata(DefaultInputFile.java:77)
at org.sonar.api.batch.fs.internal.DefaultInputFile.charset(DefaultInputFile.java:216)
at org.sonar.plugins.html.core.HtmlSensor.execute(HtmlSensor.java:106)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:34)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:78)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:51)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:69)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:51)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:68)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:122)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:108)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:418)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:414)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:372)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:122)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:108)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:126)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:122)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:108)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128)
at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: org.sonar.api.utils.MessageException: You’re not authorized to run analysis. Please contact the project administrator.


19:20:29.067 INFO: Load project repositories
19:20:29.627 DEBUG: GET 403 https://sonarcloud.io/batch/project.protobuf?key=com.yalimaytul%3Aresume | time=560ms
19:20:29.656 DEBUG: stylelint-bridge server will shutdown
19:20:29.659 INFO: ------------------------------------------------------------------------
19:20:29.660 INFO: EXECUTION FAILURE
19:20:29.660 INFO: ------------------------------------------------------------------------
19:20:29.661 INFO: Total time: 45.487s
19:20:29.772 INFO: Final Memory: 28M/97M
19:20:29.772 INFO: ------------------------------------------------------------------------
19:20:29.772 ERROR: Error during SonarQube Scanner execution
19:20:29.772 ERROR: You’re not authorized to run analysis. Please contact the project administrator.
19:20:29.772 ERROR: Caused by: You’re not authorized to run analysis. Please contact the project administrator.
19:20:29.772 ERROR:
19:20:29.772 ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! web@0.0.3 sonar: sonar-scanner
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the web@0.0.3 sonar script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

What determines the user that’s running the analysis? I created the login key with an administrator user and used the same login key to run the analysis. Why this is not working?

User is Admin, organization bound to Bitbucket, user created key is used in the call. This should be working! I’m not sure what’s missing here?

Hello @yaytul,

I’m surprised by the fact that your scanner command does not have a -Dsonar.organization parameter set. I’m quite sure it’s mandatory, but what puzzles me is the error message which is not supposed to be this one. You can give it a try anyway.

Also permission wise, your user needs:

  • only Execute Analysis if the project had been created
  • but also Create Project if the project has to be created

Finally you could double check your token.

Cheers

I have that parameter in the sonar-project.properties file; Seems I fail to mention that above.
sonar.host.url=https://sonarcloud.io
sonar.organization=…
sonar.projectName=…
sonar.projectKey=…
sonar.sourceEncoding=UTF-8
sonar.sources=src/app
sonar.exclusions=/node_modules/
sonar.tests=src/app
sonar.test.inclusions=**/*.spec.ts
sonar.javascript.lcov.reportPaths=shippable/codecoverage/lcov.info
sonar.links.homepage=…
sonar.links.ci=https://app.shippable.com/…
sonar.links.issue=https://bitbucket.org/…
sonar.links.scm=https://bitbucket.org/…

Hello,

As you are using npm run sonar, it uses NPM sonarqube-scanner. It is designed to read parameters from the command line using the standard -Dsonar.xxx=yyy syntax, so it should work.
Though as it is an additional layer, it makes sense to be sure the issue is not around this. Then I suggest you to user the regular SonarScanner CLI, with parameters in the sonar-project.properties and/or the command line.

If it doesn’t work: there is a permission problem on your organization. Make sure the user used has both Execute Analysis and Create Project (if the project has to be created).
If it works, the issue is about how you integrate in with the NPM package.

BTW, to answer your initial question:

Exactly as you did: SonarCloud will recognize that the token belongs to the user you created it from, then uses permissions of this user.

Cheers

Hey @Antoine

  • I pulled every property from the file into the command line. It still fails. See below

  • I’m building with shippable CI, I’m using an image with Node and Java11.

  • All my other builds in Java passes and I can see PRs, master analysis separately. This is the only project that fails.

  • Same key is used on other projects to run analysis. They all work without problmes.

    npm run sonar-scanner -Dsonar.login=… -Dsonar.projectVersion=0.0.7 -Dsonar.pullrequest.branch=release/0.0.7 -Dsonar.pullrequest.key=false -Dsonar.pullrequest.base= -Dsonar.issuesReport.console.enable=true -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=my_org -Dsonar.projectName=… -Dsonar.projectKey=… -Dsonar.sourceEncoding=UTF-8 -Dsonar.sources=src/app -Dsonar.exclusions=/node_modules/ -Dsonar.tests=src/app -Dsonar.test.inclusions=**/*.spec.ts -Dsonar.javascript.lcov.reportPaths=shippable/codecoverage/lcov.info -Dsonar.links.homepage=https://… -Dsonar.links.ci=https://… -Dsonar.links.issue=https://… -Dsonar.links.scm=https://… -Dsonar.pullrequest.provider=bitbucketcloud -Dsonar.pullrequest.bitbucketcloud.repository=… -Dsonar.pullrequest.bitbucketcloud.owner= -Dsonar.pullrequest.bitbucketcloud.triggerCommit=…3be039

hi @yaytul. did you ever get this to work. I have the same issue

Is this resolved? Having same issue, one particular project is failing and rest all is working.