sonar-scanner-npm
sonar-scanner-npm copied to clipboard
java: not found
Attempting to run this in an alpine-node Docker image (java is not installed).
$ sonar-scanner -DbuildNumber=$CI_JOB_ID -Dsonar.host.url=$SONAR_HOST -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASSWORD -Dsonar.projectKey=$SONAR_PROJECT_KEY
[00:23:08] Starting SonarQube analysis...
[00:23:08] Checking if executable exists: /root/.sonar/native-sonar-scanner/sonar-scanner-3.3.0.1492-linux/bin/sonar-scanner
[00:23:08] Could not find executable in "/root/.sonar/native-sonar-scanner".
[00:23:08] Proceed with download of the platform binaries for SonarQube Scanner...
[00:23:08] Creating /root/.sonar/native-sonar-scanner
[00:23:08] Downloading from https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip
[00:23:08] (executable will be saved in cache folder: /root/.sonar/native-sonar-scanner)
/root/.sonar/native-sonar-scanner/sonar-scanner-3.3.0.1492-linux/bin/sonar-scanner: exec: line 66: /root/.sonar/native-sonar-scanner/sonar-scanner-3.3.0.1492-linux/jre/bin/java: not found
ERROR: Job failed: exit code 127
Hey, have you found a fix / workaround for this one?
I ended up creating a new Dockerfile with Java installed. You'll have do download the jdk from Oracle.
ENV JAVA_HOME /opt/java/current
ENV PATH $PATH:/opt/java/current/bin
COPY packages/jdk-8u212-linux-x64.tar.gz /opt/java/jdk-8u212-linux-x64.tar.gz
# Oracle Java - https://wiki.alpinelinux.org/wiki/Installing_Oracle_Java
RUN ( \
cd /opt/java; \
tar -zxvf jdk-8u212-linux-x64.tar.gz;\
rm jdk-8u212-linux-x64.tar.gz; \
chown -R root.root jdk1.8.0_212/; \
ln -s jdk1.8.0_212 /opt/java/current; \
printf "export JAVA_HOME=/opt/java/current\nexport PATH=$PATH:\$JAVA_HOME/bin\n" > /etc/profile.d/java.sh; \
which paxctl || apk add paxctl; \
cd ./current/bin; \
paxctl -c java; \
paxctl -m java; \
paxctl -c javac; \
paxctl -m javac; \
)
It would be nice if Java wasn't needed though.
Hello,
I have the same issue on node:12-alpine in gitlab-ci pipeline.
I run in before_script to run once who failed every time just to install it:
before_script:
- apk --update add openjdk8-jre
- npm run sonar || echo 'Sonar fail'
- sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /root/.sonar/native-sonar-scanner/sonar-scanner-4.4.0.2170-linux/bin/sonar-scanner
script:
- npm run sonar
It works but it's very ugly.
Can you just put an args to set by le command line the boolean value of use_embedded_jre in sonar-scanner (sh & bat) script. To launch the cmd like this : npm run sonar -Duse_embedded_jre=false
Actually the value is hard coded :
set use_embedded_jre=true
if "%use_embedded_jre%" == "true" (
set "JAVA_HOME=%SONAR_SCANNER_HOME%\jre"
)
if not "%JAVA_HOME%" == "" goto foundJavaHome
Thanks, Edo
Has there been any follow up on this? I am still having this issue on node alpine
Thank you, Edo (@epelaic), I have improved your sed a little bit:
set -- /root/.sonar/native-sonar-scanner/* && sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' "$1/bin/sonar-scanner"
Warning! Do not thinkless copy-paste, I'm not any good Shell-developer.
@bellingard the readme says:
sonarqube-scanner makes it very easy to trigger SonarQube / SonarCloud analyses on a JavaScript code base, without needing to install any specific tool or (Java) runtime.
It looks like this is not true, it does not work without a java runtime.
Ah ok: https://github.com/bellingard/sonar-scanner-npm/issues/59#issuecomment-463603165
The link in the comment above is dead, but i found this docker image that fixes the issue for alpine by installing glibc
:
https://github.com/Docker-Hub-frolvlad/docker-alpine-glibc/blob/master/Dockerfile
Hey @fabb, would like to contribute a small PR for the readme?
Hello again everyone,
Thanks for bringing this up. I created a list of potential improvements and mentioned this topic:
- #165
I'll close this issue for now. Feel free to reopen if you want to create a PR ;)