Jenkins pipeline执行sonar-scanner失

2021-12-31  本文已影响0人  87d6dc4b11a7

当我通过以下流水线执行sonar-scanner时,提示sonar-scanner: command not found。
失败原因:PATH+bin=${sonar_home}/bin 等号两边加了空格导致失败。

node('test-agent')  {
    def sonar_home = tool name: 'sonar-scanner-4.6.2'
    withEnv(["PATH+bin=${sonar_home}/bin"]) {
        stage('代码审查'){
            withSonarQubeEnv('sonarqube-8.9.6') {
                sh "printenv"
                sh "sonar-scanner -h"
            }        
        }
    }
}

同时,还需要设置JAVA_HOME,在sonar-scanner-4.6.2.2472-linux/bin/sonar-scanner中可以看到

if [ -n "$JAVA_HOME" ]
then
  java_cmd="$JAVA_HOME/bin/java"
else
  java_cmd="`which java`"
fi

https://stackoverflow.com/questions/43643803/sonarqube-scanner-fails-in-a-jenkins-pipeline-due-to-command-not-found

上一篇下一篇

猜你喜欢

热点阅读