我已经安装并配置了SonanarQube Qualuity Gates插件,并在非pipline作业中成功配置了它。但是,当你尝试在pipline中配置它时,我遇到了不同的错误,当我尝试像这样制作pipline时:
stage ("SonarQube analysis") {
dir('source') {
def scannerHome = tool 'sonscanner';
withSonarQubeEnv('sonar'){
timeout(time: 1, unit: 'HOURS');
withSonarQubeEnv('sonar'){
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
我明白这一点:
java.lang.IllegalStateException: There is no body to invoke
at org.jenkinsci.plugins.workflow.cps.CpsStepContext.newBodyInvoker(CpsStepContext.java:283)
at org.jenkinsci.plugins.workflow.cps.CpsStepContext.newBodyInvoker(CpsStepContext.java:95)
at org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.start(TimeoutStepExecution.java:46)
在SonarQube分析之后作为单独的步骤:
stage("Quality Gate"){
timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {error "Pipeline aborted due to quality gate failure: ${qg.status}"
} else {
echo 'Quality Gate PASSED'
}
}
}
比
java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.
at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.processStepParameters(WaitForQualityGateStep.java:125)
at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:107)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:224)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:150)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)
当pipline:
stage ("SonarQube analysis") {
dir('source') {
def scannerHome = tool 'sonscanner';
withSonarQubeEnv('sonar'){
sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=android -Dsonar.sources='${WORKSPACE}'/source -Dsonar.language=java -Dsonar.projectBaseDir='${WORKSPACE}'/source -Dsonar.java.binaries='${WORKSPACE}'/source/app/build/intermediates/classes/debug -Dsonar.junit.reportsPath='${WORKSPACE}'/sourceapp/build/test-results/testDebugUnitTest"
}
}
}
stage("Quality Gate"){
timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {error "Pipeline aborted due to quality gate failure: ${qg.status}"
} else {
echo 'Quality Gate PASSED'
}
}
}
这:
Caused: java.lang.IllegalStateException: Unable to parse response from https://sonar//api/ce/task?id=AWCYPE3v1VuUrqmUzLyR: