Analyze .NET Core solution with SonarCloud and Github Actions

Hi,

I’d like to analyze my .NET Core solution with SonarCloud in Github Actions.
Is this a supported scenario?
I followed the instructions at SonarCloud Scan · Actions · GitHub Marketplace · GitHub and added the SonarCloud step to my workflow:

  • name: SonarCloud Scan
    uses: sonarsource/sonarcloud-github-action@master
    env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

It fails with the following error:

Run sonarsource/sonarcloud-github-action@master
env:
DOTNET_ROOT: C:\hostedtoolcache\windows\dncs\2.2.108\x64
GITHUB_TOKEN: ***
SONAR_TOKEN:
##[error]Container action is only supported on Linux

I configured the SONAR_TOKEN in my GitHub settings as suggested, but I don’t see any GITHUB_TOKEN in my repo secrets. Is that a built-in token on Github?

Update: Resolved.
My GitHub Actions workflow was configured for Windows. This was no problem up until the SonarCloud task. I now configured it to run on Linux and now the workflow succeeds across the board.

name: .NET Core
on: [push]
jobs:
   build:
        runs-on: ubuntu-latest
1 Like

Hi!

I’m curious how well the Action https://github.com/marketplace/actions/sonarcloud-scan worked? On the marketplace page it lists .NET solutions under “Do not use this GitHub action if you are in the following situations” I guess it’s because the action uses the SonarScanner CLI instead of the SonarScanner for MSBuild/DotNet Core.

I was looking around for alternatives in other Sonar DotNet Core Actions in the marketplace, but I couldn’t find anyone that supported pull request decoration. So I developed my own Action for this:

1 Like

I am not having good luck trying to get this to work… So, they are probably correct.

I’m not using the action from the market place any more.
Instead, in my GitHub Actions workflow, I install the global tool dotnet-sonarscanner to analyze my code.
As a prereq, I’m also installing Java in a step for the global tool to work.

You can see an example here:

1 Like