Launching Sonar Scanner from a Gitlab Docker Runner

Launching Sonar Scanner from a gitlab docker runner

After further investigations i can say that i made a working docker image for sonar scanner that can work with gitlab ci.

DOCKERFILE

FROM openjdk:8

LABEL maintainer="Aria Groult <aria.groult@outlook.fr>"

RUN apt-get update
RUN apt-get install -y curl git tmux htop maven sudo

# Install Node - allows for scanning of Typescript
RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
RUN sudo apt-get install -y nodejs build-essential

WORKDIR /usr/src

RUN curl --insecure -o ./sonarscanner.zip -L https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.0.3.778-linux.zip && \
unzip sonarscanner.zip && \
rm sonarscanner.zip && \
mv sonar-scanner-3.0.3.778-linux /usr/lib/sonar-scanner && \
ln -s /usr/lib/sonar-scanner/bin/sonar-scanner /usr/local/bin/sonar-scanner

ENV SONAR_RUNNER_HOME=/usr/lib/sonar-scanner
COPY sonar-scanner-run.sh /usr/bin
RUN ["chmod", "+x", "/usr/bin/sonar-scanner-run.sh"]

You might get problems with the embedded JRE in sonar-scanner. If it happens, modify the binary by setting: useembeddedjava to false.

gitlab-ci.yml & sonar-scanner-run.sh are unchanged

sonar-project.properties

sonar.projectKey=projectkey
sonar.projectName=projectname
sonar.sourceEncoding=UTF-8
sonar.exclusions=node_modules/**,coverage/**
sonar.sources=./components
sonar.gitlab.project_id=linkToGit
sonar.host.url=hosturl
sonar.login=sonarqubeloginkey
sonar.exclusions=test/**, node_modules/**

It is important to specify that node_modules are excluded in a nodejs project since they include some java files that will create some disfonctionment in the sonar-scanner process. In general only include un-generated files in the sonar-scanner file list

Sonar scanner command found on Gitlab CI/CD

It looks like the

- sonar-scanner -Dsonar.qualitygate.wait=true

command is not found. Try to run that command on the machine you are setting up your pipeline (like ssh into that machine or ssh into it and try running that command). The issue might be that it isn't installed on there.

GitLab-CI: sonar-scanner : The term 'sonar-scanner' is not recognized as the name of a cmdlet, function,

My issue was related to environment path. I have multiple accounts.

  • GitLab Runner Service as Admin and has full access to Sonar-Scanner directory

The account that GitLab runner was using was not the account that had the environment variables. Once SonarScanner directory was added to the user environment variables (Path) of the GitLab runner windows account, it worked as expected.



Related Topics



Leave a reply



Submit