Writing libraries Accessing steps At the base level, any valid Groovy code is okay for use. Different data structures, utility methods, etc, such as: Library classes cannot directly call steps such as  sh  or  git . They can however implement methods, outside of the scope of an enclosing class, which in turn invoke Pipeline steps, for example: This approach has limitations; for example, it prevents the declaration of a superclass. Which can then be called from a Scripted Pipeline: Alternately, a set of  steps  can be passed explicitly using  this  to a library class, in a constructor, or just one method: When saving state on classes, such as above, the class  must  implement the  Serializable  interface. 67 package org.foo class Utilities implements Serializable {  def steps  Utilities(steps) {this.steps = steps}  def mvn(args) { steps.sh "${steps.tool 'Maven'}/bin/mvn -o ${args}"  } } def z = new org.foo.Zot() z.checkOutFrom(repo) // src/org/foo/Zot.groovy package org.foo; def checkOutFrom(repo) {  git url: "git@github.com:jenkinsci/${repo}" } // src/org/foo/Point.groovy package org.foo; // point in 3D space class Point {  float x,y,z; }