I want to reorganize my Jenkins script pipeline into classes for readability and reuse.
The problem is that I get exceptions when doing this. Consider a simple example:
When i run
echo currentBuild.toString()
everything is good
But when I fetch it into the class as follows:
class MyClass implements Serializable { def runBuild() { echo currentBuild.toString() } } new MyClass().runBuild()
I get an exception:
Started by user admin Replayed #196 [Pipeline] End of Pipeline groovy.lang.MissingPropertyException: No such property: currentBuild for class: MyClass
What is the correct way to extract code in classes?
jenkins refactoring groovy jenkins-pipeline jenkinsfile
et
source share