This ensures that a Pipeline using the class, as seen in the example below, can properly suspend and resume in Jenkins. 

@Library('utils') import org.foo.Utilities def utils = new Utilities(this) node {  utils.mvn 'clean package' } 

If the library needs to access global variables, such as env , those should be explicitly passed into the library classes, or methods, in a similar manner. 

Instead of passing numerous variables from the Scripted Pipeline into a library, 

package org.foo class Utilities {  static def mvn(script, args) { script.sh "${script.tool 'Maven'}/bin/mvn -s ${script.env.HOME}/jenkins.xml -o ${args}"  } } 

The above example shows the script being passed in to one static  method, invoked from a Scripted Pipeline as follows: 

@Library('utils') import static org.foo.Utilities.* node {  mvn this, 'clean package' } 

## Defining global variables 

Internally, scripts in the vars  directory are instantiated on-demand as singletons. This allows multiple methods to be defined in a single .groovy  file for convenience. For example: 

var/log.groovy 

def info(message) { echo "INFO: ${message}" } def warning(message) { echo "WARNING: ${message}" } 

