#vars/variables.groovy
def setFoo(f) {
this.foo = f
}
def isFoo() {
return this.foo
}
#src/com/company/ci/Build.groovy
void execute() {
def foo = false
if (env.BRANCH_NAME.equals("master")) {
foo = true
}
variables.setFoo(foo)
}
#Jenkinsfile
def build = new com.company.ci.Build()
build.execute()
def foo = variables.isFoo()if (foo) {
println "We got foo"
}
groovy.lang.MissingPropertyException: No such property: foo for class: variables
Possible solutions: foo
If I use variables.foo or if I change isFoo() to getFoo() it calls getFoo countless times and hangs.
I am not sure what I am doing wrong here. Any clues?
I have no problem accessing variables.getFoo() within Build.groovy, but not in the Jenkinsfile afterwards.