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

Improve docs for shared libraries in Declarative Pipeline

      Existing docs about writing Shared Libraries are mostly cover an old 'Scripted Pipeline'.

      I have a shared library which perfectly works when pipeline is defined in a 'scripted' manner. However, it doesn't work when I use new 'Declarative' pipeline syntax.

      Here's the "variable" code which leads to StackOverflowException on Jenkins. Can't figure out why.

      // vars/buildStage.groovy
      import io.oscript.buildSteps

      def call(body){

        def steps = new buildSteps()

        body.resolveStrategy = Closure.DELEGATE_FIRST
        body.delegate = steps
        body()
      }

      In the scripted pipeline this variable encloses methods of my build. All steps are implemented in buildSteps class, and every method is symply a 'bat $script'

      Here's Declarative pipeline fragment

      steps {

          buildStage {

          {

             clean() // main method

            }

      }

      Call to this library causes StackOverflowException on Jenkins.

      java.lang.StackOverflowError
      at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1318)
      at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3368)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:132)

      If you switch back to old syntax, it works.

      So, here's the request: Please improve Shared Libraries documentation and tell us how to write Shared Libraries for Declarative Syntax.

      My sources are attached.

       

       

          [JENKINS-44542] Improve docs for shared libraries in Declarative Pipeline

          Andrei Ovsiankin created issue -
          Andrei Ovsiankin made changes -
          Description Original: Existing docs about writing Shared Libraries are mostly cover an old 'Scripted Pipeline'.

          I have a shared library which perfectly works when pipeline is defined in a 'scripted' manner. However, it doesn't work when I use new 'Declarative' pipeline syntax.

          Here's the "variable" code which leads to StackOverflowException on Jenkins. Can't figure out why.

          {{// vars/buildStage.groovy}}
           {{import io.oscript.buildSteps}}

          {{def call(body)\{}}

          {{  def steps = new buildSteps()}}

          {{  body.resolveStrategy = Closure.DELEGATE_FIRST}}
           {{  body.delegate = steps}}
           {{  body()}}
           {{}}}

          In the scripted pipeline this variable encloses methods of my build. all steps implemented in buildSteps class, and method is symply 'bat $script'

          Here's Declarative pipeline fragment

          {{steps \{}}

          {{    buildStage }}

          {{    \{}}

          {{       clean() // main method}}

          {{    }}}

          {{}}}

          Call to this library causes StackOverflowException on Jenkins.

          java.lang.StackOverflowError
           at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1318)
           at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3368)
           at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:132)

          If you switch back to old syntax, it works.

          So, here's the request: Please improve Shared Libraries documentation and tell us how to write Shared Libraries for Declarative Syntax.

          My sources are attached.

           

           
          New: Existing docs about writing Shared Libraries are mostly cover an old 'Scripted Pipeline'.

          I have a shared library which perfectly works when pipeline is defined in a 'scripted' manner. However, it doesn't work when I use new 'Declarative' pipeline syntax.

          Here's the "variable" code which leads to StackOverflowException on Jenkins. Can't figure out why.

          {{// vars/buildStage.groovy}}
           {{import io.oscript.buildSteps}}

          {{def call(body)\{}}

          {{  def steps = new buildSteps()}}

          {{  body.resolveStrategy = Closure.DELEGATE_FIRST}}
           {{  body.delegate = steps}}
           {{  body()}}
           {{}}}

          In the scripted pipeline this variable encloses methods of my build. all steps implemented in buildSteps class, and method is symply 'bat $script'

          Here's Declarative pipeline fragment

          {{steps \{}}

              buildStage \{

          {{    \{}}

          {{       clean() // main method}}

                }

          {{}}}

          Call to this library causes StackOverflowException on Jenkins.

          java.lang.StackOverflowError
           at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1318)
           at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3368)
           at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:132)

          If you switch back to old syntax, it works.

          So, here's the request: Please improve Shared Libraries documentation and tell us how to write Shared Libraries for Declarative Syntax.

          My sources are attached.

           

           
          Andrei Ovsiankin made changes -
          Description Original: Existing docs about writing Shared Libraries are mostly cover an old 'Scripted Pipeline'.

          I have a shared library which perfectly works when pipeline is defined in a 'scripted' manner. However, it doesn't work when I use new 'Declarative' pipeline syntax.

          Here's the "variable" code which leads to StackOverflowException on Jenkins. Can't figure out why.

          {{// vars/buildStage.groovy}}
           {{import io.oscript.buildSteps}}

          {{def call(body)\{}}

          {{  def steps = new buildSteps()}}

          {{  body.resolveStrategy = Closure.DELEGATE_FIRST}}
           {{  body.delegate = steps}}
           {{  body()}}
           {{}}}

          In the scripted pipeline this variable encloses methods of my build. all steps implemented in buildSteps class, and method is symply 'bat $script'

          Here's Declarative pipeline fragment

          {{steps \{}}

              buildStage \{

          {{    \{}}

          {{       clean() // main method}}

                }

          {{}}}

          Call to this library causes StackOverflowException on Jenkins.

          java.lang.StackOverflowError
           at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1318)
           at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3368)
           at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:132)

          If you switch back to old syntax, it works.

          So, here's the request: Please improve Shared Libraries documentation and tell us how to write Shared Libraries for Declarative Syntax.

          My sources are attached.

           

           
          New: Existing docs about writing Shared Libraries are mostly cover an old 'Scripted Pipeline'.

          I have a shared library which perfectly works when pipeline is defined in a 'scripted' manner. However, it doesn't work when I use new 'Declarative' pipeline syntax.

          Here's the "variable" code which leads to StackOverflowException on Jenkins. Can't figure out why.

          {{// vars/buildStage.groovy}}
           {{import io.oscript.buildSteps}}

          {{def call(body)\{}}

          {{  def steps = new buildSteps()}}

          {{  body.resolveStrategy = Closure.DELEGATE_FIRST}}
           {{  body.delegate = steps}}
           {{  body()}}
           {{}}}

          In the scripted pipeline this variable encloses methods of my build. All steps are implemented in *buildSteps* class, and every method is symply a 'bat $script'

          Here's Declarative pipeline fragment

          {{steps \{}}

              buildStage \{

          {{    \{}}

          {{       clean() // main method}}

                }

          {{}}}

          Call to this library causes StackOverflowException on Jenkins.

          java.lang.StackOverflowError
           at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1318)
           at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3368)
           at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:132)

          If you switch back to old syntax, it works.

          So, here's the request: Please improve Shared Libraries documentation and tell us how to write Shared Libraries for Declarative Syntax.

          My sources are attached.

           

           
          James Dumay made changes -
          Epic Link New: JENKINS-45382 [ 183542 ]
          Andrew Bayer made changes -
          Assignee Original: Andrew Bayer [ abayer ]

            Unassigned Unassigned
            evilbeaver Andrei Ovsiankin
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: