[英]Jenkins pipeline script error WorkflowScript: Expected a step
I have created a testcase from a much bigger Jenkins pipeline project and it works fine.我从一个更大的 Jenkins 管道项目创建了一个测试用例,它工作正常。
pipeline {
agent none
stages {
stage ("Check Parameters")
{
steps {
echo "In pipeline"
script {
echo "Start condition check"
}
build job: 'printuser'
//def slaveJob = build job: 'printuser'
//println slaveJob.rawBuild.log
}
}
}
}
Howevr, inorder to get the output of printuser job onto the pipeline i comment build job: 'printuser' and uncomment the slaveJob code as below:但是,为了将 printuser 作业的 output 放到管道上,我注释 build job: 'printuser' 并取消注释 slaveJob 代码,如下所示:
//build job: 'printuser'
def slaveJob = build job: 'printuser'
println slaveJob.rawBuild.log
It now fails with the below error:它现在失败并出现以下错误:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 13: Expected a step @ line 13, column 15.
def slaveJob = build job: 'printuser'
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:126)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:522)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:320)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
Can you please suggest what is the issue here?你能建议这里有什么问题吗?
If you want to use groovy, you must put it inside the script
section, not outside:如果你想使用 groovy,你必须把它放在
script
部分里面,而不是外面:
script {
echo "Start condition check"
build job: 'printuser'
def slaveJob = build job: 'printuser'
println slaveJob.rawBuild.log
}
PS: not sure your code will work as such, but you should at least put it inside the script
part. PS:不确定您的代码是否可以正常工作,但您至少应该将其放在
script
部分中。 Outside of the script
closure, jenkins
will only accept a set of predefined steps .在
script
关闭之外, jenkins
将只接受一组预定义的步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.