How to extract sections of Jenkins pipeline script into classes? How to extract sections of Jenkins pipeline script into classes? jenkins jenkins

How to extract sections of Jenkins pipeline script into classes?


You are on the right way, but the problem is that you didn't pass the script object to the instance of your class and was trying to call method which is not defined in the class that you have created.

Here is one way to solve this:

// Jenkins file or pipeline scripts editor in your jobnew MyClass(this).runBuild()// Class declarationclass MyClass implements Serializable {    def script    MyClass(def script) {        this.script=script    }    def runBuild() {        script.echo script.currentBuild.toString()    }}


your code missing declare class field script

class MyClass implements Serializable {    def script    MyClass(def script) {        this.script=script    }    def runBuild() {        script.echo script.currentBuild.toString()    }}

this code should be ok @bram