Search code examples
sonarqubesonar-runnergo-cd

How to add sonar scanner in GoCD?


I am creating a GoCD pipeline to run sonar analysis for my project. Up to now, I have successfully configured sonar properties on my local file and it successfully pushes the metrics to the sonar server.

The problem occurs when creating a GoCD pipeline to run the analysis. I am unable to successfully install sonar scanner on GoCD agents. The error that I get when executing command sonar scanner from the pipeline is "SONAR_RUNNER_HOME does not point to a valid installation directory".


Solution

  • Currently We are running sonar-scanner from GoCD pipeline and checking SonarQube Quality Gates correctly.

    What we do was the following: I created a bash script that launch the sonar-scanner. This script (and other ones used by our GoCD configuation) is inside a second Git Material (the first one is the Project source code). We have installed the 'SonarQube Quality Gates Task Plugin' to evaluate our SonarQube quality gates.

    So we have a Job in our Pipeline with the following tasks:

    1. Type: Custom Command --- Run if: Passed --- Command: /bin/bash --- Arguments: path_to_sonar_scanner_bash_script_launcher.sh --- Working Directory: your_working_dir
    2. Type: SonarQube - Quality Gate --- Run if: Passed --- Key of the SonarQube project: sonar_qube_project_id --- Fail Quality Gate result: error Sonar --- Api Url: http://your_sonar:9000/api

    We have GoCD agent and sonarqube installed in the same machine.

    I expect this help you.