Groovy Variables

Groovy variables enable more complex mapping of data. It could be that status or date needs to be mapped to other values.



Available scopes

The groovy script has the following objects / variables available

Variable name

Description

Note

Variable name

Description

Note

issue

the current issue that the call is operating on

 

response

the parent response from the previous runned call as String 

 

jsonSlurper

Use JsonSlurper

Does not work with  Groovy 3.0.7 and OpenJDK 64bit 11.0.13+8 (https://issues.apache.org/jira/browse/GROOVY-9802 )
See workaround below

jsonOutput

Use JsonSlurper

Does not work with  Groovy 3.0.7 and OpenJDK 64bit 11.0.13+8 (https://issues.apache.org/jira/browse/GROOVY-9802 )
See workaround below

scope

all previous defined variables or responses

Example if call A get
name = Peter as json response
then call B that get
the an issue with all its properties

then call C and c wants to access name it can do so by using

scope.name



 

 

Common Error

Exception in your groovy code java.lang.RuntimeException: Unable to load FastStringService

Workaround

Workaround is to use ObjectMapper instead of JSON Slurper

Parse JSON

import com.fasterxml.jackson.databind.ObjectMapper ObjectMapper mapper = new ObjectMapper() //response is passed in from the parent action def myRespnse = mapper.readValue(response, HashMap.class)

Produce JSON

def myList = [] myList.add([email:issue.reporter.emailAddress]) return mapper.writeValueAsString(myList)




See examples