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

Cannot use function calls in shared library step

      When trying to implement a declarative pipeline inside of a shared library step, I'm finding that this only works if the pipeline is defined inside the "call" method.  As soon as I add a function call, I start seeing exceptions.

       

      Working code:

      def call() {
        pipeline {
          agent any
      
          stages {
            stage("Stage") {
              steps {
                echo "hi"
              }
            }
          }
        }
      } 

       

      Non-working code:

      def call() {
        execute()
      }
      
      def execute() {
        pipeline {
          agent any
      
          stages {
            stage("Stage") {
              steps {
                echo "hi"
              }
            }
          }
        }
      } 

       

      Error message:

      hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: any for class

       

      For reasons beyond this post, we are trying to add some commonality and argument checking to our steps, which is why I'd like to be able to use that concept of the extra function call...

       

          [JENKINS-63290] Cannot use function calls in shared library step

          Christopher Shannon created issue -
          Christopher Shannon made changes -
          Description Original: When trying to implement a declarative pipeline inside of a shared library step, I'm finding that this only works if the pipeline is defined inside the "call" method.  As soon as I add a function call, I start seeing exceptions.

           

          Working code:

          {{```}}

          {{def call() {}}

          {{  pipeline {}}

          {{    agent any}}

           

          {{    stages {}}

          {{      stage("Stage") {}}

          {{        steps {}}

          {{          echo "hi"}}

          {{        }}}

          {{      }}}

          {{    }}}

          {{  }}}

          {{}}}

          {{```}}

          Non-working code:

          {{```}}

          {{def call() {}}

          {{  execute()}}

          {{}}}

           

          {{def execute() {}}

          {{  pipeline {}}

          {{    agent any}}

           

          {{    stages {}}

          {{      stage("Stage") {}}

          {{        steps {}}

          {{          echo "hi"}}

          {{        }}}

          {{      }}}

          {{    }}}

          {{  }}}

          {{}}}

          {{```}}

          Error message:

          {{```}}

          {{{{hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: any for class}}}}

           

          {{```}}

          For reasons beyond this post, we are trying to add some commonality and argument checking to our steps, which is why I'd like to be able to use that concept of the extra function call...

           
          New: When trying to implement a declarative pipeline inside of a shared library step, I'm finding that this only works if the pipeline is defined inside the "call" method.  As soon as I add a function call, I start seeing exceptions.

           

          Working code:

          {{def call() {}}

          {{  pipeline {}}

          {{    agent any}}

           

          {{    stages {}}

          {{      stage("Stage") {}}

          {{        steps {}}

          {{          echo "hi"}}

          {{        }}}

          {{      }}}

          {{    }}}

          {{  }}}

          {{}}}

           

          Non-working code:

          {{def call() {}}

          {{  execute()}}

          {{}}}

           

          {{def execute() {}}

          {{  pipeline {}}

          {{    agent any}}

           

          {{    stages {}}

          {{      stage("Stage") {}}

          {{        steps {}}

          {{          echo "hi"}}

          {{        }}}

          {{      }}}

          {{    }}}

          {{  }}}

          {{}}}

           

          Error message:

          {{hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: any for class}}

           

          For reasons beyond this post, we are trying to add some commonality and argument checking to our steps, which is why I'd like to be able to use that concept of the extra function call...

           
          Christopher Shannon made changes -
          Description Original: When trying to implement a declarative pipeline inside of a shared library step, I'm finding that this only works if the pipeline is defined inside the "call" method.  As soon as I add a function call, I start seeing exceptions.

           

          Working code:

          {{def call() {}}

          {{  pipeline {}}

          {{    agent any}}

           

          {{    stages {}}

          {{      stage("Stage") {}}

          {{        steps {}}

          {{          echo "hi"}}

          {{        }}}

          {{      }}}

          {{    }}}

          {{  }}}

          {{}}}

           

          Non-working code:

          {{def call() {}}

          {{  execute()}}

          {{}}}

           

          {{def execute() {}}

          {{  pipeline {}}

          {{    agent any}}

           

          {{    stages {}}

          {{      stage("Stage") {}}

          {{        steps {}}

          {{          echo "hi"}}

          {{        }}}

          {{      }}}

          {{    }}}

          {{  }}}

          {{}}}

           

          Error message:

          {{hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: any for class}}

           

          For reasons beyond this post, we are trying to add some commonality and argument checking to our steps, which is why I'd like to be able to use that concept of the extra function call...

           
          New: When trying to implement a declarative pipeline inside of a shared library step, I'm finding that this only works if the pipeline is defined inside the "call" method.  As soon as I add a function call, I start seeing exceptions.

           

          Working code:
          {code:java}
          def call() {
            pipeline {
              agent any

              stages {
                stage("Stage") {
                  steps {
                    echo "hi"
                  }
                }
              }
            }
          } {code}
           

          Non-working code:
          {code:java}
          def call() {
            execute()
          }

          def execute() {
            pipeline {
              agent any

              stages {
                stage("Stage") {
                  steps {
                    echo "hi"
                  }
                }
              }
            }
          } {code}
           

          Error message:

          {{hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: any for class}}

           

          For reasons beyond this post, we are trying to add some commonality and argument checking to our steps, which is why I'd like to be able to use that concept of the extra function call...

           
          Jesse Glick made changes -
          Component/s Original: pipeline [ 21692 ]
          Labels Original: jenkins pipeline shared-libraries New: shared-libraries
          Devin Nusbaum made changes -
          Link New: This issue relates to JENKINS-46547 [ JENKINS-46547 ]

            Unassigned Unassigned
            w60001 Christopher Shannon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: