skip to Main Content

I am trying to set up Sonarqube with GitHub Action. I followed the manual step by step but could not get it to work. It seems that the connection to the local server is failing and therefore the SonarScanner could not execute. I also tried using a self-hosted runner on a Windows PC but unfortunately the container action is only supported on linux.

This is the build.yml file:

name: Build
on:
  push:
    branches:
      - main # or the name of your main branch
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - uses: sonarsource/sonarqube-scan-action@master
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
      # If you wish to fail your job when the Quality Gate is red, uncomment the
      # following lines. This would typically be used to fail a deployment.
      # - uses: sonarsource/sonarqube-quality-gate-action@master
      #   timeout-minutes: 5
      #   env:
      #     SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Secrets have been configured as it stands in the SonarQube manual. Value for the SONAR_HOST_URL is http://localhost:9000 and for SONAR_TOKEN the previously generated token using the SonarQube token generator.
The sonar-project.properties file is also setup as the manual says (just copy and paste).

Error for this configuration:

Run sonarsource/sonarqube-scan-action@master
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /github/workspace/sonar-project.properties
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.14 Alpine (64-bit)
INFO: Linux 5.13.0-1031-azure amd64
INFO: User cache: /opt/sonar-scanner/.sonar/cache
ERROR: SonarQube server [***] can not be reached
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.343s
ERROR: Error during SonarScanner execution
INFO: Final Memory: 3M/14M
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis

If runs-on is changed to self-hosted (self-hosted runner is configured and set up), i get this error:

Run sonarsource/sonarqube-scan-action@master
Error: Container action is only supported on Linux

Did anyone had the same problem or knows how tho fix this?
Help would be much appreciated, since i am new to both SonarQube and GitHub Actions

2

Answers


  1. I cannot help you with not reachable part as I’m also facing the same issue but as for the self-hosted, make sure you are using Linux environment for sonarqube action. It doesn’t accept mac or Windows runner.

    Login or Signup to reply.
  2. From your configuration I don’t see how you are creating a SonarQube Server at localhost:9000. Each GitHub Action job runs in its own runner environment. Unless you build the server in the same runner environment you cannot reach localhost. If you have done this please show us the configuration. Otherwise, use the address of a SonarQube server hosted elsewhere that the GitHub Action can reach.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search