Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Groovy Libraries allow custom Groovy functions and helpers to be shared and reused across all Groovy scripts in FlexDeploy

Table of Contents
maxLevel6
minLevel1
include
outlinefalse
indent
exclude^Groovy Libraries allow
stylenone
typelist
printabletrue
class

...

LIB_LOGGER

Code Block
languagegroovy
// this WOULD work in the way LIB_PIPELINE_UTILS is using it
static void logMessage(String message)
{
  // log
}

//
this would NOT work in the way LIB_PIPELINE_UTILS is using it
void logMessagelogMessage2(String message)
{
  // log
}

...

Code Block
languagegroovy
import com.flexagon.groovy.custom.LIB_LOGGER;

def loggerInstance = new LIB_LOGGER(LOG);

void myPipelineFunction()
{
  // This WILL work
  LIB_LOGGER.logMessage("Logger library static method")
  
  // This will NOT work
  LIB_LOGGER.logMessage2("Logger library instance method")
  
  // code omitted for brevity
} BOTH of these will work
  loggerInstance.logMessage("Logger library static method")
  loggerInstance.logMessage2("Logger library instance method")
}
Note

Static method caveat

A final note on static methods - Static methods cannot access instance variables. This means if you have a static method defined in your library and try to access FLEXDEPLOY, LOGor any other instance variables it will not work and produce an error like the following: You attempted to reference a variable in the binding or an instance variable from a static context.

In this case you must either remove the static modifier or not use the variable in question.

Circular Imports

Warning

Circular imports of custom libraries are not allowed and if found an error will be thrown [Circular imports detected. Please check if libraries are creating instances of each other outside of a function scope..] when attempting to test or save the library.

...