我在 Jenkins 管道中创建了一个这样的类。
class Device
{
def ip = null
def context
def getIP(devName)
{
return "aaa.bbb.ccc.ddd"
}
Device(context, devName, devType)
{
print("[DEBUG] ctor device")
ip = getIP(devName)
this.context = context
print(ip)
}
}
ap = new Device(this, "DEV", "TYPE")
print ap.ip
Run Code Online (Sandbox Code Playgroud)
当我在“Groovy Web 控制台”( https://groovyconsole.appspot.com/ ) 中尝试它时效果很好,但是当我在 Jenkins 中运行此脚本时,会出现以下错误。
[Pipeline] Start of Pipeline
expected to call Device.<init> but wound up catching Device.getIP; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/
[Pipeline] End of Pipeline
hudson.remoting.ProxyException: CpsCallableInvocation{methodName=getIP, call=com.cloudbees.groovy.cps.impl.CpsFunction@20fd33e6, receiver=Device@57905ade, arguments=[DEV]}
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)
剧本有什么问题吗?