Must be a way in Jenkinsfile to access variables set within a Shared 
Library script.
I could set a return variable for execute(), not a good solutions if I want 
to access more than one variable.

def build = new com.company.ci.Build()
def foo = build.execute()

Unless I can return the variables object.
def build = new com.company.ci.Build()
def variables = build.execute()
def foo = variables.getFoo()
def bar = variables.getBar()


mandag 19. desember 2016 12.52.59 UTC+1 skrev Sverre Moe følgende:
>
> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/f5cf2221-330a-43a7-b280-a8ac1ad15ed6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to