我想对git存储库代码执行SonarQube分析,并且我想从Docker Container中使用SonarScanner,而不是从Jenkins Configuration中使用。
我尝试创建此管道:
pipeline {
agent { docker { image 'emeraldsquad/sonar-scanner:latest' } }
stages {
stage('build && SonarQube analysis') {
steps {
withSonarQubeEnv('sonar.tools.devops.****') {
sh 'sonar-scanner \\ -Dsonar.projectKey=myProject \\ -Dsonar.sources=./src \\'
}
}
}
stage("Quality Gate") {
steps {
timeout(time: 1, unit: 'HOURS') {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
// Requires SonarScanner for Jenkins 2.7+
waitForQualityGate abortPipeline: true
}
}
}
}
}
在阶段构建&& SonarQube分析中,构建失败,并显示构建输出:
Injecting SonarQube environment variables using the configuration: sonar.tools.devops.*****
[Pipeline] {
[Pipeline] sh
+ sonar-scanner ' -Dsonar.projectKey=myProject' ' -Dsonar.sources=./src' '\'
ERROR: Unrecognized option: -Dsonar.sources=./src
INFO:
INFO: usage: sonar-scanner [options]
INFO:
INFO: Options:
INFO: -D,--define <arg> Define property
INFO: -h,--help Display help information
INFO: -v,--version Display version information
INFO: -X,--debug Produce execution debug output
答案 0 :(得分:0)
我会尝试删除参数之间的双反斜杠:
sh 'sonar-scanner -Dsonar.projectKey=myProject -Dsonar.sources=./src'
反斜杠转义符转义空格,不会被shell截断,而是添加到参数的名称中。