When building and running a github action, the secret is missing from my sonarcloud.io. The build fails but the error is displayed as a warning and 5 lines later, the build outputs 0 warnings. I think this should be an error and the build should fail.
Logs example:
08:10:55.315 Updating build integration targets…
08:10:55.711 WARNING: Authentication with the server has failed.
I faced the same behavior.
I would also prefer the auth warning to be an error instead so that the actions workflow fails at this point.
Furthermore, I could resolve the issue by recreating the sonarqube cloud token and update the value in GitHub actions secrets. However, I was wondering why my former token was not there anymore in SonarQube Cloud. Any idea? Was this erased while the migration of the plans by Sonar?
Thank you @Colin for the hint. Seems to match, yes. My token was inactive for more than 60 days. This automatic deactivation is unexpected and imho unintentional (i.e. if you set it up for a project that is in maintenance mode and gets updates every half a year for example).
Find my example (incl. GitHub actions workflow) here. For an example of the warning log entry, see this run
My expected behavior requires WARNING: Authentication with the server has failed. to be an error (throw exception!?) instead of just logging a warning.
@Martin_Strecker thank you for your investigations and for the reply! Much appreciated.
I just tested the recommendations and it seems like it didn’t work as expected (see here). Build command still gets executed.
@Martin_Strecker seems to me like the main method of the dotnet-sonarscanner should return void or may Task instead of Task<int> to make it work as expected - otherwise the Environment.ExitCode property gets ignore as far as I understand from the docs.
It looks like your workflows run on windows-latest with Powershell Desktop.
$PSNativeCommandUseErrorActionPreference is supported on Powershell Core 7.4. and above only. Please change the shell to pwsh. See also here for more details:
See also this discussion on GitHub actions which is exactly about your problem:
Regarding the exit code you are right, in the sense that Environment.ExitCode is ignored, but we also return the right exit code from main, so that it is still propagated:
> dotnet-sonarscanner begin
...
Expecting at least the following command line argument:
...
Pre-processing failed. Exit code: 1
> $LASTEXITCODE
1
@Martin_Strecker thanks for analyzing and investigation! Much appreciated.
I just changed the shell to pwsh, added $ErrorActionPreference = "Stop" and $PSNativeCommandUseErrorActionPreference = $true and now it seems to work as expected.
@rufer7 I’m glad to hear it worked and thank you for your patience.
To be honest, it’s not really intuitive that ErrorActionPreference and PSNativeCommandUseErrorActionPreference have to be set.
We agree, but there is nothing we can do to improve the situation, except updating our documentation by adopting your setup (Powershell Core and “fail-fast”). I created a ticket for our documentation team to do this.
Maybe Github Actions change the default for scripts in the future, but this would be a breaking change and will likely not happen.