I have a Jmeter script with many HTTP Requests, each with a JSR223 preprocessor. Most of the preprocessors have common code and I want to reference that code from one place, not necessarily functions but a large piece of code that is duplicated in all preprocessors. I've experimented with a few things and I came across in the Jmeter documentation the mention of storing a script in a JSR223 Sampler and then in a variable and then referencing the variable with ${__groovy(${RANDOM_NAME})}.
https://jmeter.apache.org/usermanual/best-practices.html#developing_scripts
https://jmeter.apache.org/usermanual/functions.html#how
I cannot find any examples of this working in a real script. I understand most of this but I am not sure how "it can be stored as a variable on the Test Plan". I have the code in a JSR223 sample in a thread group that is called before all others but am not sure how to store it as a variable. Can someone please show me a working example of this?
