It is common that you will need to pass variables between elements, and there are a number of ways to do this. Some ways are more readable than others, so consider the maintainability of how you do this.
Table of Contents |
---|
Magic Globals
api.global and api.local are very useful mechanisms for caching data, but accessing & mutating entries inside them between multiple elements quickly gets messy.
...
This code is much easier to debug and refactor than the first version.
Api.Global for Caching
Consider the same example as above, where we need to cache the result of the query data:
...
Using this strategy, we have an explicit sequence of events. It is very easy to see where the data came from, and debug/refactor it.
Injected Scoped Variables in Lib Methods
Consider the following, where DataLibrary.groovy is a groovy library that can be called from any logic:
...