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

Improve docs for shared libraries in Declarative Pipeline

    XMLWordPrintable

    Details

    • Similar Issues:
    • Epic Link:

      Description

      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.

       

       

        Attachments

          Activity

          There are no comments yet on this issue.

            People

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

              Dates

              Created:
              Updated: