Sonar scanner plugin not available inside docker container

I’m trying to run sonar scanner inside a docker image of npm and sonar scanner seems to be unavailable.

/var/lib/jenkins/workspace/onarTest_Mit-Surgical-UI_develop@tmp/durable-691fdd16/script.sh: 1: /var/lib/jenkins/workspace/onarTest_Mit-Surgical-UI_develop@tmp/durable-691fdd16/script.sh: /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sqScannerNx/bin/sonar-scanner: not found
[Pipeline] }

Outside the docker container, on the docker agent I’m able to run the sonar-scanner
Any inputs on this issue?

Thanks,
Krishna
$ docker top bc0949b52df7a11fb6b91c2cbeee11362b76a361496ce07b572cff46618f91d1 -eo pid,comm
$ docker stop --time=1 bc0949b52df7a11fb6b91c2cbeee11362b76a361496ce07b572cff46618f91d1
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
$ docker rm -f bc0949b52df7a11fb6b91c2cbeee11362b76a361496ce07b572cff46618f91d1
WARN: Unable to locate ‘report-task.txt’ in the workspace. Did the SonarScanner succeeded?

@krishnaarani were you able to figure this out? I am having the same issue I think.

Yes, I was able to resolve that
I had to mount the Sonar scanner home to a directory volume inside the docker
Looks something like this on my end

buildConfig.buildImage =

                            withCredentials([string(credentialsId: "login-jenkins", variable: 'sonarkey')]) {

                                docker.withRegistry(buildConfig.ascRegistry, buildConfig.ascRegistryCredID) {

                                    docker.image("docker/${buildConfig.buildImage}").pull()

                                    sh "mkdir -p $scannerHomeDocker"

                                    **docker.image("docker/${buildConfig.buildImage}").inside("-v ${scannerHome}:${scannerHomeDocker}"){**

                                        sh "${scannerHomeDocker}/bin/sonar-scanner" +

                                        " -Dsonar.host.url=${buildConfig.sonarUrl}" +

                                        " -Dsonar.login=${sonarkey}"
1 Like