在Jenkins中使用waitForQualityGate()
步骤运行多分支管道作业时,Jenkins抛出groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: status for class: org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$QGStatus
错误。
waitForQualityGate()
适用于正常的管道项目,选中Use Groovy Sandbox
选项。
waitForQualityGate()
以及Sonar Scanner for MSBuild的代码。
void endSonarMSBuild() {
if (env.BRANCH_NAME == 'develop') {
stage('Complete SonarQube Analysis') {
withSonarQubeEnv('civil sonar') {
def MSBuildScannerHome = tool 'sonar-scanner-msbuild-3.0.0.629';
bat "${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe end"
}
}
stage("Quality Gate") {
timeout(time: 1, unit: 'MINUTES') {
def qg = waitForQualityGate()
if ((qg.status = 'ERROR')) {
error "Pipeline aborted due to quality gate failure"
}
}
}
} else {
echo "Skipping stage since the current branch is: ${env.BRANCH_NAME}"
}
}
相同的代码适用于普通管道作业,但不适用于多分支管道作业。任何帮助表示赞赏。
完整的Jenkins错误日志如下:
groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: status for class: org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$QGStatus
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2744)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3770)
at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:201)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:484)
at org.kohsuke.groovy.sandbox.impl.Checker$5.call(Checker.java:300)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onSetProperty(GroovyInterceptor.java:68)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onSetProperty(SandboxInterceptor.java:182)
at org.kohsuke.groovy.sandbox.impl.Checker$5.call(Checker.java:297)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedSetProperty(Checker.java:294)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.setProperty(SandboxInvoker.java:32)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawSet(PropertyAccessBlock.java:24)
at WorkflowScript.endSonarMSBuild(WorkflowScript:177)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.set(PropertyishBlock.java:88)
at com.cloudbees.groovy.cps.impl.AssignmentBlock$ContinuationImpl.assignAndDone(AssignmentBlock.java:70)
at sun.reflect.GeneratedMethodAccessor718.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:74)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:165)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:330)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:242)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:230)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:0)
waitForQualityGate()与Multi Branch Pipeline作业完美配合。这是一个非常愚蠢的错误导致了这里提到的问题。
我没有像if ((qg.status == 'ERROR'))
那样比较qg状态,而是尝试分配值if ((qg.status = 'ERROR'))
。相当愚蠢的错误。