-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
-
Jenkins ver. 2.46.3 OS: Windows Server 2012
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.