I have a Jenkins shared lib in a repo, usual folder structure:
vars
utils.groovy
In utils.groovy I have some functions:
void funcA() {}
void funcB() {}
Now I want to define a constant that all functions in that module can use, but when I try this:
String common='hi'
void funcA() {println "A ${common}"}
void funcB() {println "B ${common}"}
I get an exception that common is not a symbol that exists:
groovy.lang.MissingPropertyException: No such property: common for class: utils
For now I'm getting around the issue by doing this hack:
String _getCommon() {
return 'hi'
}
void funcA() {String common=_getCommon(); println "A ${common}"}
void funcB() {String common=_getCommon(); println "B ${common}"}