Created
March 26, 2025 11:38
-
-
Save brunojhovany/9bf6013b9889ac73fbd7524972d68fb8 to your computer and use it in GitHub Desktop.
Sonarqube scanner for .Net framework GitHub actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: SonarQube Analysis | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| env: | |
| SOLUTION_PATH: 'YourSolution.sln' # Ruta a tu solución | |
| SONAR_PROJECT_KEY: 'YourProjectKey' # Clave única de tu proyecto en SonarQube | |
| DOTNET_VERSION: '4.7' # Versión de .NET Framework | |
| jobs: | |
| sonarqube-analysis: | |
| name: SonarQube Analysis | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Necesario para análisis completo de SonarQube | |
| - name: Setup .NET Framework | |
| uses: actions/setup-dotnet@v3 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Install SonarScanner | |
| run: | | |
| nuget install MSBuild.SonarQube.Runner.Tool -version 5.11.0 -ExcludeVersion -OutputDirectory $env:USERPROFILE\.sonar\scanner | |
| - name: Initialize SonarQube Scanner | |
| uses: SonarSource/[email protected] | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Necesario para PR decoration | |
| with: | |
| scanner-mode: 'MSBuild' | |
| args: > | |
| /k:"${{ env.SONAR_PROJECT_KEY }}" | |
| /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" | |
| /d:sonar.exclusions="**/bin/**/*,**/obj/**/*" | |
| /d:sonar.verbose=true | |
| - name: Build with MSBuild and SonarQube | |
| run: | | |
| $SCANNER_PATH = "$env:USERPROFILE\.sonar\scanner\MSBuild.SonarQube.Runner.Tool\tools\SonarScanner.MSBuild.exe" | |
| # Inicio de análisis SonarQube | |
| & "$SCANNER_PATH" begin /k:"${{ env.SONAR_PROJECT_KEY }}" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" | |
| # Restauración y compilación | |
| msbuild ${{ env.SOLUTION_PATH }} /t:Restore | |
| msbuild ${{ env.SOLUTION_PATH }} /p:Configuration=Release /p:Platform="Any CPU" /p:DebugType=portable | |
| # Finalización de análisis SonarQube | |
| & "$SCANNER_PATH" end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" | |
| # Opcional: Esperar resultado del Quality Gate | |
| - name: SonarQube Quality Gate Check | |
| uses: SonarSource/[email protected] | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment