我想对git仓库代码执行SonarQube分析,我想从Docker容器中使用SonarScanner,而不是从Jenkins配置中使用。
我试着建立这个管道:
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
1条答案
按热度按时间r7knjye21#
我会尝试删除参数之间的双反斜杠:
sh 'sonar-scanner -Dsonar.projectKey=myProject -Dsonar.sources=./src'
反斜杠用于转义shell不会中断的空格,并添加到参数名称中。