Run SonarCloud for .net on Linux agent in GitHub Actions

Hey there,

I’m currently trying to integrate SonarCloud in GitHub Actions to analyze .net6 build & test results. The example build.yml that is proposed by SonarCloud for .Net solutions and GitHub Actions is only available for windows agents. However, since you can’t use Linux Docker containers on windows agents and I have to start a container with an image that is only available for Linux in order to execute integration tests, I have to exclude the integration tests from the pipeline.
Is there any possibility to run SonarCloud for .net on Linux agents in GitHub Actions?

Best,
David

Hey there.

It should be as easy as switching the image named in the tutorial to ubuntu-latest and converting the Powershell. I tried this and it worked as expected (minus some of the caching steps)

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 1.11
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - name: Cache SonarCloud packages
        uses: actions/cache@v1
        with:
          path: ~\sonar\cache
          key: ${{ runner.os }}-sonar
          restore-keys: ${{ runner.os }}-sonar
      - name: Install SonarCloud scanners
        run: |
          dotnet tool install --global dotnet-sonarscanner
      - name: Build and analyze
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        run: |
          dotnet-sonarscanner begin /k:"colin-sonarsource_dotnet_core_sample" /o:"colin-sonarsource" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
          dotnet build
          dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"

I think it’s a bit annoying we don’t have a more generic example (or a second tutorial for Linux). I’ll flag it as something we should consider.

Hey Colin,

Thanks for flagging this for consideration, and of course for the yml. I’ll try it in the next couple of day when I have time!

David

Tried it today - works like a charm. Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.