Using the Groovy Definition Type

Groovy is a programming language that is recommended for data processing. It requires the Groovy runtime, which requires a JVM.

Variables and Parameters

You can define variables meant to hold intermediary values the same way you define normal variables in Groovy, using the standard syntax int myVar or myVar = "initial value".

Process Definition parameters are available directly in Groovy as Java variables, as shown in the examples below.

Note: If a process reaches status Error, the Out values of parameters are not set. You can use a Post Running action to set them if required.

Examples

This example retrieves the sample XML music catalog from w3schools, parses the XML, prints some information from it, and store the number of CDs in the Out parameter OutParameter1.

Copy
println "Getting Music Catalog"
catalog = "http://www.w3schools.com/xml/cd_catalog.xml".toURL().text
cds = new XmlSlurper().parseText(catalog)
cds.CD.each {
  println it.ARTIST.text()+":  " + it.TITLE.text()
}

// One is missing
println "Simon & Garfunkel: 'The 59th Street Bridge Song'"

//Store number of CDs in OutParameter1, defined on the Process Definition
OutParameter1 = cds.CD.size()

This example creates an XML listing of a directory path specified in the Parameter1 Process Definition parameter.

Copy
//Parameter1 is a String parameter defined on the process
def xml = new groovy.xml.MarkupBuilder()
File dir = new File(Parameter1)
xml.files(type:"current dir list")
{
  dir.eachFile
  { f ->
    file(f.getName())
  }
}