I try to set up a simple CI pipeline in gitlab with sonarqube. I don't know how I can start the sonarqube server inside the CI pipeline and access it.
I tried the following CI pipeline:
image: sonarsource/sonar-scanner-cli:latest stages: - sonarqube sonarqube: stage: sonarqube script: - whoami - sonar-scanner -X -Dsonar.projectKey=[my_key] -Dsonar.sources=. only: - feature/create_webpage tags: - large timeout: 120m I have set the environment variable SONAR_HOST_URL to http://localhost:9000 and started it on that port before locally but that cannot be reached via the pipeline. Before I have tried it with SONAR_HOST_URL=http://sonarqube:9000 but I got the same error, that it is not reachable. The output from whoami was scanner-cli.
I also tried the CI pipeline with node image. Please regard only the stage "sonarqube", the test stage is irrelevant.
image: node:22.9.0 services: - name: sonarqube:latest alias: sonarqube stages: - test - sonarqube variables: SONAR_SCANNER_CLI_VERSION: "4.6.2.2472" SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache cache: key: "${CI_COMMIT_REF_SLUG}" paths: - .sonar/cache before_script: - npm install -g npm@latest - npm install -g sonar-scanner --unsafe-perm - chmod +x /usr/local/lib/node_modules/sonar-scanner/bin/sonar-scanner test: stage: test script: - npm install - npm install --save-dev mocha chai chai-http sinon - chmod +x getStockData.sh - npm test tags: - large timeout: 120m sonarqube: stage: sonarqube script: - whoami - sonar-scanner -X -Dsonar.projectKey=[my_key] -Dsonar.sources=. -Dsonar.host.url=http://sonarqube:9000 only: - feature/create_webpage tags: - large timeout: 120m Here I got this permissions error:
$ whoami root $ sonar-scanner -X -Dsonar.projectKey=[my_key] -Dsonar.sources=. -Dsonar.host.url=http://sonarqube:9000 /usr/local/lib/node_modules/sonar-scanner/bin/sonar-scanner: 59: exec: : Permission denied