Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55113

Constructor, using other methods of the class, causes "hudson.remoting.ProxyException: com.cloudbees.groovy.cps.impl.CpsCallableInvocation"

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Using the constructor, which calls to another public method of the class causes "hudson.remoting.ProxyException: com.cloudbees.groovy.cps.impl.CpsCallableInvocation" on execution:

      pipeline {
          agent none
          stages {
              stage('Processing projects') {
                  agent {label 'master'}
                  steps {
                      script {
                          def example = new Example(3)
                          println(example.getNumber())
                      }
                  }
              }
          }
      }
      
      public class Example {
          private int a;
      
          public Example() {
              a = 0;
          }
      
          public Example(int base) {
              this();
              addDoubled(base);
          }
      
          public void addDoubled(int base) {
              a += base * 2;
          }
      
          public int getNumber() {
              return a;
          }
      }
      

      Using the same class without using such constructor works fine:

      pipeline {
          agent none
          stages {
              stage('Processing projects') {
                  agent {label 'master'}
                  steps {
                      script {
                          def example = new Example()
                          example.addDoubled(3)
                          println(example.getNumber())
                      }
                  }
              }
          }
      }
      
      public class Example {
          private int a;
      
          public Example() {
              a = 0;
          }
      
          public Example(int base) {
              this();
              addDoubled(base);
          }
      
          public void addDoubled(int base) {
              a += base * 2;
          }
      
          public int getNumber() {
              return a;
          }
      }
      

        Attachments

          Issue Links

            Activity

            Hide
            dnusbaum Devin Nusbaum added a comment -

            Unfortunately, this cannot be fixed if the method is CPS-transformed, see JENKINS-26313 for details.

            If your method does not call any Pipeline steps then you should be able to annotate it with @NonCPS so that it does not get CPS-transformed, which should prevent the issue from happening and allow you to call it from a constructor.

            Show
            dnusbaum Devin Nusbaum added a comment - Unfortunately, this cannot be fixed if the method is CPS-transformed, see JENKINS-26313 for details. If your method does not call any Pipeline steps then you should be able to annotate it with @NonCPS so that it does not get CPS-transformed, which should prevent the issue from happening and allow you to call it from a constructor.
            Hide
            alpanshin Alexandr Panshin added a comment -

            Thank you for clarification and workaround, Devin!

            Show
            alpanshin Alexandr Panshin added a comment - Thank you for clarification and workaround, Devin!

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              alpanshin Alexandr Panshin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: