Sonar scan docker image node -v Is Node.js available during analysis

Tools:
Sonarqube Community: Latest via docker
Sonar Scanner Docker Image: sonarsource/sonar-scanner-cli

When running the docker image on any Javascript repository this error occurs:
ERROR: Error when running: 'node -v'. Is Node.js available during analysis?

Since this docker image doesn’t work with node I’ve also attempted writing my own docker image to replace this one and tried everything I could possibly think of to get node to work in the scan, there is no reason why the sonar scanner shouldn’t be able to find node, yet from Java it doesn’t seem to be able to call it.

My own docker image I’ve implemented sonar scanner like so and replicated the same node error found in sonarsource/sonar-scanner-cli:

ENV SONAR_SCANNER_VERSION=5.0.1.3006 \
    SONAR_SCANNER_HOME=/opt/sonar-scanner

RUN curl --create-dirs -sSLo /tmp/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip && \
    unzip /tmp/sonar-scanner.zip -d /opt && \
    rm /tmp/sonar-scanner.zip && \
    ln -s /opt/sonar-scanner-*/bin/sonar-scanner /usr/local/bin/sonar-scanner

ENV PATH="${SONAR_SCANNER_HOME}/bin:${PATH}"

I have discovered this issue was introduced post 4.7 switching back to sonar scanner 4.7.0.2747 resolves this issue.

Hello @willpercey-gb, thank you for your post, and welcome to our Community!

Could you provide your entire Dockerfile, please? I tried to replicate it locally like this:

FROM sonarsource/sonar-scanner-cli

ENV SONAR_SCANNER_VERSION=5.0.1.3006 \
    SONAR_SCANNER_HOME=/opt/sonar-scanner

RUN curl --create-dirs -sSLo /tmp/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip && \
    unzip /tmp/sonar-scanner.zip -d /opt && \
    rm /tmp/sonar-scanner.zip && \
    ln -s /opt/sonar-scanner-*/bin/sonar-scanner /usr/local/bin/sonar-scanner

ENV PATH="${SONAR_SCANNER_HOME}/bin:${PATH}"

But I think I’m missing something because I got this error:

Dockerfile:6
--------------------
   5 |
   6 | >>> RUN curl --create-dirs -sSLo /tmp/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip && \
   7 | >>>     unzip /tmp/sonar-scanner.zip -d /opt && \
   8 | >>>     rm /tmp/sonar-scanner.zip && \
   9 | >>>     ln -s /opt/sonar-scanner-*/bin/sonar-scanner /usr/local/bin/sonar-scanner
  10 |
--------------------
ERROR: failed to solve: process "/bin/sh -c curl --create-dirs -sSLo /tmp/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip &&     unzip /tmp/sonar-scanner.zip -d /opt &&     rm /tmp/sonar-scanner.zip &&     ln -s /opt/sonar-scanner-*/bin/sonar-scanner /usr/local/bin/sonar-scanner" did not complete successfully: exit code: 1

I tried also the following, but I was unable to reproduce your issue:

  • Scanning a project with the most recent sonar-scanner-cli image (docker run -v $(pwd):/usr/src sonarsource/sonar-scanner-cli);
  • Looking for the node binary inside the sonar-scanner-cli image on versions latest, 4.8.0 and 4.7:
$ for version in latest 4.8.0 4.7; do docker run sonarsource/sonar-scanner-cli:${version} node -v ; done
v18.17.1
v18.17.0
v18.12.1

Regards.

1 Like