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

Cannot use function calls in shared library step

    XMLWordPrintable

Details

    Description

      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...

       

      Attachments

        Issue Links

          Activity

            w60001 Christopher Shannon created issue -
            w60001 Christopher Shannon made changes -
            Field Original Value New Value
            Description 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...

             
            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...

             
            w60001 Christopher Shannon made changes -
            Description 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...

             
            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...

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

            People

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

              Dates

                Created:
                Updated: