I have a CI workflow that integrates a linting job and then a code quality job. My Linting job is a docker runner launching my eslint script from the application code. Then my code quality job is supposed to start a sonar scanner docker instance, check my code and send the reports back to my sonarqube instance.
The problem is mainly with the fact that i can't launch correctly the sonar scanner with either solutions which are :
Sonar Scanner Docker
https://github.com/newtmitch/docker-sonar-scanner
At this point, the runner runs the image but when starting its script (which is only sonar-scanner (with potential arguments)
i get this error response :
sonar scanner unrecognized option -c
which i don't understand and have no control over since its an already made docker image pulled from the docker hub
Sonar Scanner installation from scratch in a docker container
Here what i do is installing sonar scanner by downloading it in the container like so:
Dockerfile
FROM java:alpine
ENV SONAR_SCANNER_VERSION 3.3.0.1492
RUN apk add --no-cache wget && \
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip && \
unzip sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux && \
cd /usr/bin && ln -s /sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux/bin/sonar-scanner sonar-scanner && \
apk del wget
COPY sonar-scanner-run.sh /usr/bin
RUN ["chmod", "+x", "/usr/bin/sonar-scanner-run.sh"]
Here I add wget to be able to download files, then I download the latest version of sonar-scanner from the link found on their official documentation. I then unzip it and then create a symlink to the binary file so that I can execute the script from anywhere. I finally clear the wget cache copy my shell script that will be executed from the gitlab-ci.yml and run a chmod command to bypass any permission problems.
sonar-scanner-run.sh
URL="https://mysonarqubeserver"
USER="myusertoken"
SONAR_PROJECT_KEY="myprojectkey"
COMMAND="sonar-scanner -Dsonar.host.url=\"$URL\" -Dsonar.login=\"$USER\" -Dsonar.projectKey=\"$SONAR_PROJECT_KEY\""
eval $COMMAND
the environment variables are all given by sonarqube after you create a project.
Here I have what I think is a "Linux Problem" where my symlink is not created since I get this error code in my gitlab ci logs :
Unkown command sonar-scanner
EDIT The symlink now works (problem was that the unziped folder name wasn't correct) but another message pops off. The sonar scanner actually works now here is the error:
INFO: ------------- Run sensors on module mytherapy
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=121ms
INFO: Sensor JavaSquidSensor [java]
INFO: Configured Java source version (sonar.java.source): none
INFO: JavaClasspath initialization
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 14.285s
ERROR: Error during SonarQube Scanner execution
INFO: Final Memory: 25M/284M
INFO: ------------------------------------------------------------------------
ERROR: Please provide compiled classes of your project with sonar.java.binaries property
My project is a react-native, therefore javascript project. I don't understand why it is requiring java compiled classes
Here is my gitlab-ci.yml file in case a problem might be from here:
gitlab.ci.yml
cache:
paths:
- node_modules/
stages:
- analysis
- test
lint:
stage: analysis
image: "node:latest"
script: npm i && npm run lint
tags: ["nodejs"]
code quality:
stage: analysis
image: <My image from the registry>
script:
- /usr/bin/sonar-scanner-run.sh
pass tests:
stage: test
image: "node:latest"
script: npm i && npm run test
tags: ["nodejs"]