I create a class in Jenkins pipeline like this.
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
It works well when I try it in the 'Groovy web console' (https://groovyconsole.appspot.com/) But when I run this script in Jenkins, the following error occurs.
[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
What's wrong with the script?