Error while running sonarqube from Jenkins as sonar-scanner Permission denied

Viewed 45

Below is the error from Jenkins console output:

+ sonar-scanner -Dsonar.login=**** -Dsonar.projectBaseDir=.
/var/lib/jenkins/workspace/Mtr-Pipeline_develop@2@tmp/durable-0080bcff/script.sh: 1: /var/lib/jenkins/workspace/Mtr-Pipeline_develop@2@tmp/durable-0080bcff/script.sh: sonar-scanner: Permission denied

I have setup the token and pasted the key in t-m-sonar-login variable in Jenkins global credentials.But I dont think it should be the keys causing `permission denied error. Can someone provide some pointers to look into the issue.

stage('SonarQube scan') {
    agent {
        dockerfile { filename 'sonar/Dockerfile' }
    }
    steps {
        withCredentials([string(credentialsId: 't-m-sonar-login', variable: 'SONAR_LOGIN')]) {
            script {
                unstash 'coverage'
                unstash 'testResults'
                sh 'sonar-scanner -Dsonar.login="$SONAR_LOGIN" -Dsonar.projectBaseDir=. || true'
            }
        }

    }
}
    

sonar/Dockerfile:

FROM node:15-buster

################
# Install java #
################
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive \
    apt-get -y install openjdk-11-jre-headless && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

############################
# Install SonarQube client #
############################
WORKDIR /root

RUN apt-get install -y curl grep sed unzip
RUN curl --insecure -o ./sonarscanner.zip -L https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.4.0.2170-linux.zip
RUN unzip -q sonarscanner.zip
RUN rm sonarscanner.zip
RUN mv sonar-scanner-4.4.0.2170-linux sonar-scanner

ENV SONAR_RUNNER_HOME=/root/sonar-scanner
ENV PATH $PATH:/root/sonar-scanner/bin

# Include Sonar configuration and project paths
COPY ./sonar/sonar-runner.properties ./sonar-scanner/conf/sonar-scanner.properties

# Ensure Sonar uses the provided Java for musl instead of a borked glibc one
RUN sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /root/sonar-scanner/bin/sonar-scanner
1 Answers

Please check whether Java is available on the system where SonarQube Scanner is running. Another thing you can try is: Go to SonarQube Scanner Directory -> Go to bin -> chmod +x sonar-scanner

Related