Is it a problem with scope perhaps?

Tried setting foo first before calling build.execute()
variables.setFoo(true)
def build = new com.company.ci.Build()
build.execute()

def foo = variables.isFoo()
if (foo) {
  println "We got foo"
} else{
  println "No foo"
}

Within build.execute() it sets foo to false, but it does not seem the 
Jenkinsfile is aware if that. 
Is it creating two instances of variables, one for Build and one for 
Jenkinsfile?

torsdag 15. desember 2016 11.11.35 UTC+1 skrev Sverre Moe følgende:
>
>
> https://github.com/jenkinsci/workflow-cps-global-lib-plugin#defining-global-variables
>
> #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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/1c80ee21-c490-4dc6-a94c-8edf11df8211%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to