ScaryGhast ScaryGhast - 3 months ago 48
Groovy Question

What's the syntax to create a Serializable Groovy Class for Jenkins Workflow/Pipeline

Working with Jenkins Workflow Groovy, I'm running into Serialization errors when trying to create objects for a dead simple class. What kind of syntactic sugar is required to pass the serializable test? The following code is failing. Adding the @Serializable line fails with "class java.io.Serializable is not an annotation in @java.io.Serializable"

//@Serializable
class TestClass {
def hello() {
println "halloooo"
}
}
def myobj = TestClass.newInstance()
node () {
myobj.hello()
}

Answer

Credit to izzekil for answering this.

class TestClass implements Serializable {}