[英]hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.call() is applicable
I am getting "No signature" error when the body() method calls in my pipeline groovy script当 body() 方法在我的管道 groovy 脚本中调用时,我收到“无签名”错误
I was using Jenkins shared library for pipeline project.我正在使用 Jenkins 共享库进行管道项目。 I have configured the shared library in my local Jenkins.
我已经在本地 Jenkins 中配置了共享库。 When I tried to hit my shared library, it is getting called properly but I am not able to resolve the parameters values which is coming in my shared library
call()
method.当我尝试访问我的共享库时,它被正确调用,但我无法解析共享库
call()
方法中的参数值。
My Share Library code ( myDeliveryPipeline.groovy
)我的共享库代码 (
myDeliveryPipeline.groovy
)
def call(body) {
println(body)
// evaluate the body block, and collect configuration into the object
def pipelineParams= [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = pipelineParams
body()
println (pipelineParams.BRANCH)
println 'Map'
println body
println 'pipelineParams'
println pipelineParams
println 'Start pipeline steps'
// our complete declarative pipeline can go in here
pipeline {
agent any
// Stage checkout git
stages {
stage('checkout git') {
steps{
git branch: 'master', url:'MY_GIT_HUB_URL'
}
}
//checkout git ends
// stage build
stage('build') {
steps{
script{
if(isUnix()){
sh 'mvn clean package -Dmaven.test.skip=true'
}
else{
bat('mvn clean install -Dmaven.test.skip=true')
}
}
}
}
// stage build ends
// stage Test
stage ('test') {
steps{
script{
if('yes' == 'yes'){
if(isUnix()){
parallel (
"unit tests": { sh 'mvn test' },
"integration tests": { sh 'mvn integration-test' }
)
}
else{
parallel (
"unit tests": { bat('mvn test')},
"integration tests": { bat('mvn integration-test')}
)
}
}
}
}
}
// stage Test Ends
}
post {
failure {
mail to: 'MAIL_ID@gmail.com', subject: 'Pipeline failed', body: "${env.BUILD_URL}"
}
success{
println "SUCCESS"
}
}
}
}
My Jenkins File我的詹金斯文件
properties ([
parameters([
string(name: 'BRANCH', defaultValue: 'master', description: 'Branch to build'),
choice(name: 'RUN_TEST', choices: ['yes', 'no'], description: 'Run test while build'),
booleanParam(name: 'MAIL_TRIGGER', defaultValue: true, description: 'mail to be triggred'),
string(name: 'EMAIL', defaultValue: 'MY_EMAIL@gmail.com', description: 'Mail to be notified')
])
])
@Library('my-pipeline-library') _
myDeliveryPipeline(BRANCH:params.BRANCH, RUN_TEST:params.RUN_TEST, MAIL_TRIGGER:params.MAIL_TRIGGER, EMAIL:params.EMAIL)
Logs from my job我的工作日志
> C:\Program Files\Git\bin\git.exe rev-list --no-walk 2fdeb821e0ecec40e53b2e0bdd6608840914422b # timeout=10
[Pipeline] properties
[Pipeline] echo
{BRANCH=master, RUN_TEST=yes, MAIL_TRIGGER=true, EMAIL=MAIL_ID@gmail.com}
[Pipeline] End of Pipeline
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.call() is applicable for argument types: () values: []
Possible solutions: wait(), any(), wait(long), any(groovy.lang.Closure), take(int), any(groovy.lang.Closure)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
at myDeliveryPipeline.call(C:\Program Files (x86)\Jenkins\jobs\TestJenkinsFile\builds\43\libs\my-pipeline-library\vars\myDeliveryPipeline.groovy:10)
at WorkflowScript.run(WorkflowScript:14)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:77)
at sun.reflect.GeneratedMethodAccessor255.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
In the shared library file vars/myDeliveryPipeline.groovy
, the signature of call
is call(<Closure>)
.在共享库文件
vars/myDeliveryPipeline.groovy
, call
的签名是call(<Closure>)
。
However, I see you are calling it as it is call(<Map>)
.但是,我看到您正在调用它,因为它是
call(<Map>)
。
Thus, call it :因此,称之为:
myDeliveryPipeline {
BRANCH=params.BRANCH
RUN_TEST=params.RUN_TEST
MAIL_TRIGGER=params.MAIL_TRIGGER
EMAIL=params.EMAIL
}
Instead of : myDeliveryPipeline(BRANCH:params.BRANCH, RUN_TEST:params.RUN_TEST, MAIL_TRIGGER:params.MAIL_TRIGGER, EMAIL:params.EMAIL)
.而不是:
myDeliveryPipeline(BRANCH:params.BRANCH, RUN_TEST:params.RUN_TEST, MAIL_TRIGGER:params.MAIL_TRIGGER, EMAIL:params.EMAIL)
。
By now, the signature is fixed, but I can see that you override the DELEGATION of the closure (body) from Jenkins to a Map.到目前为止,签名已修复,但我可以看到您将闭包(主体)的 DELEGATION 从 Jenkins 覆盖到 Map。 As consequence,
params
is undefined.因此,
params
是未定义的。
Thus, I suggest to overload call(<Closure>)
with call(<Map>, <Closure>)
.因此,我建议使用
call(<Map>, <Closure>)
重载call(<Closure>)
call(<Map>, <Closure>)
。
def call(body) {
call([:], body)
}
def call(pipelineParams, body) {
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = pipelineParams
body()
//...
}
By now, the call can be :现在,调用可以是:
myDeliveryPipeline(
BRANCH:params.BRANCH,
RUN_TEST:params.RUN_TEST,
MAIL_TRIGGER:params.MAIL_TRIGGER,
EMAIL:params.EMAIL
) {}
Do not forget the last {}
.不要忘记最后一个
{}
。
Briefly :简要地 :
If you want to inject pipeline variables (ie: params,...) , inject them in Map
using signature myDeliveryPipeline(Map,Closure)
even if the closure is empty.如果要注入管道变量:(即参数,可以...),将它们注入在
Map
使用签名myDeliveryPipeline(Map,Closure)
即使关闭是空的。
If you are not depending on Pipeline variables, you can use Closure
by using the signature myDeliveryPipeline(Closure)
如果你不依赖于管道的变量,你可以使用
Closure
使用签名myDeliveryPipeline(Closure)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.