I run this code through jenkins pipeline(shared library).
enum Components {
  service('name_api')
  Components(String componentName) {
    this.componentName = componentName
  }
  private String componentName
  String getComponentName() {
    return componentName
  }
  static boolean isValid(String name) {
    for (Components component : values()) {
      if (component.getComponentName().equalsIgnoreCase(name)) {
        return true
      }
    }
    println("The name of component is incorrect")
  }
}
It works locally, but in Jenkins pipeline, I get this error:
hudson.remoting.ProxyException:         
com.cloudbees.groovy.cps.impl.CpsCallableInvocation
help me please
Something is wrong with groovy interpreter in that Jenkins. I'm trying to write a library and have the same error.
I made an example of pipeline script. I wrote different classes to avoid induced errors:
class Test1 {
    private t1
    private wfs
    Test1(Test2 t2, wfs) {
        this.wfs = wfs
        wfs.echo 'TEST1 constructor'
        this.t1 = t2.getT2() }
    def getT1() {
        wfs.echo 'getT1() function'
        def result = t1.toString()
        return result }
}
class Test2 {
    private t2
    private wfs
    Test2(wfs) {
        this.wfs = wfs
        wfs.echo 'TEST2 constructor'
        this.t2 = "hello" }
    def getT2() {
        wfs.echo 'getT2() function'
        def result = t2.toString()
        return result }
}
echo 'Creating Test2 object'
Test2 test2 = new Test2(this)
echo "Test2 object was created successfully. test2.t2="+test2.getT2()
echo 'Creating Test1 object'
Test1 test1 = new Test1(test2,this)
echo "Test1 object was created successfully. test1.t1="+test1.getT1()
output on this script is:
Started by user admin
[Pipeline] echo
Creating Test2 object
[Pipeline] echo
TEST2 constructor
[Pipeline] echo
getT2() function
[Pipeline] echo
Test2 object was created successfully. test2.t2=hello
[Pipeline] echo
Creating Test1 object
[Pipeline] echo
TEST1 constructor
[Pipeline] End of Pipeline
com.cloudbees.groovy.cps.impl.CpsCallableInvocation
Finished: FAILURE
The problem is in this string this.t1 = t2.getT2(). It turns out that t2.getT2() function could not be done inside constructor :(
And 2nd one - if you try return like this:
def getT1() {
    wfs.echo 'getT1()' 
    return t1.toString() 
}
It will fail...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With