Here in the @Field annotation documentation written that:
The annotated variable will become a private field of the script class.
But this is not working in Jenkins:
If i have two scripts, one of them loaded another one, @Field annotated variable becomes global:
/* test.groovy */
import groovy.transform.Field
@Field def scriptPrivateVar
def main() {
node('main') {
cleanWs()
checkout scm
scriptPrivateVar = 'a'
def module = load("${pwd()}/module.groovy")
module.callPrivate()
}
}
main()
module:
/* module.groovy */
def callPrivate() {
echo "private var: ${this.scriptPrivateVar}"
}
return this
And the output is:
20:59:32 private var: a
Am i understand correctly that the only way to make scriptPrivateVar global in scope of on only test.groovy script → define it as global without @Field? Any options?