Sonarcloud: YML file - what to use as clean build command

1.8k views Asked by At

I’ve been trying to scan a project written in C# in Sonarcloud and when I write the .github/workflows/build.yml file, I should “Replace <insert_your_build_command> by the actual one”. Maybe I’m a bit stupid but I have no clue what I should use as the build command.

Maybe someone here has an answer to this :)

Thanks!

2

There are 2 answers

0
SIS0 On BEST ANSWER

The Replace <insert_your_build_command> by the actual one should mean you should replace it with the steps you do to build your project. In your case, since it seems to be a dotnet project, following can be inserted:

dotnet build

Please update if it works.

0
Felipe Augusto On

I will share my full file in GitHub Action, that I´m using to build using OS ubuntu and send unit tests to SonarQube Cloud

name: Build on sonar

on:
  push:
    branches:
      - sonarqube
  pull_request:
    types: [opened, synchronize, reopened]
    
  workflow_dispatch:
    
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: Install SonarCloud scanner
        if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
        run: |
          dotnet tool install --global dotnet-sonarscanner

      - name: Setup .NET
        uses: actions/setup-dotnet@v2
        with:
          dotnet-version: 6.0.301
          
      - name: Install Report Generator
        run: dotnet tool install --global dotnet-reportgenerator-globaltool

      - name: Build and analyze
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        #shell: powershell
        run: |
          dotnet-sonarscanner begin /k:"felipementel_PotatoStore" /o:"felipementel" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
          dotnet restore ./src/Potato.Product.sln
          dotnet build ./src/Potato.Product.sln --configuration Release
          dotnet test ./src/Tests/Potato.Product.Api.Test/Potato.Product.Api.Test.csproj --collect:"XPlat Code Coverage" --logger trx --results-directory $GITHUB_WORKSPACE/test/testresults
          reportgenerator -reports:$GITHUB_WORKSPACE/test/testresults/**/coverage.cobertura.xml -targetdir:$GITHUB_WORKSPACE/test/coverlet/reports -reporttypes:"SonarQube"
          dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"