I am running into a 401 running the Gradle sonar task when it comes to accessing the Sonar Cloud API server. The problem occurs with the 6.x relase of the Gradle plugin and only in my GH Action.
Executing it locally or with the latest 5.x release of the plugin is no problem.
Execution failed for task ':sonar'.
> java.lang.IllegalStateException: Error status returned by url [https://api.sonarcloud.io/analysis/jres?os=linux&arch=x86_64]: 401
Thanks for the fast feedback, @Colin, and sorry for not directly referring to the workflow file.
If I can somehow assist in further testing, please reach out. I guess we should be able to see the behaviour on a fork or perhaps pull-request.
Of course, that’s clear. I was also wondering why I do not even see the usual *** for a hidden secret in the output. However, the pipeline works with the Sonar 5.x Gradle plugin, but fails with 6.x without any other change.
For either your project/organization, you probably have Execute Analysis permissions set to Anyone. This is a very bad idea, because it means that anybody (authenticated to SonarQube or not) could run an analysis against your project. Eventually, we want to get rid of this option altogether.
So why is it working with v5 of the Scanner for Gradle but not v6? Probably an error on our part. v6 of the Scanner for Gradle calls an API (to support JRE auto-provisioning) that requires authentication, even if you have granted the Execute Analysis permissions to Anyone.
Now, this isn’t great – SonarQube Cloud should do what it says it will do (allow anybody to execute analysis). I’ll raise that as an issue for our team to look at. With that being said, I really don’t recommend that you allow anyone to execute analysis.
Now, I still don’t know why, when you set SONAR_TOKEN, you don’t see it configured correctly. In my runs, I see the *** I expect to see.
If I were you, I’d try setting some other variables and seeing if you get the same results (do they show up as null or ***? Is it specific to the Gradle step or does it happen in other steps as well?)