All,

I'm trying to turn my Jenkinsfile into a library, but unfortunately I'm not 
much of a groovy programmer. I initially put several functions into my 
Jenkinsfile library, like this:

*def do_something1() {*
* ...*
*}*

*def do_something2() {*
* ...*
*}*

and called it with this from another Jenkinsfile:

*fileLoader.withGit('[email protected]:chef/Jenkinsfiles.git', 'master', 
<creds>', 'Jenkins Agent (Devops)') {*
*  pipeline = fileLoader.load('pipeline');*
*}*

*pipeline.do_something1()*
*pipeline.do_something2()*

However, I also need to make sure everything happens on the same node. If I 
change my library to this:

*def do_something1() {*
*  node (**Jenkins Agent (Devops)' {*
*    ...*
*  }*
*}*

*def do_something2() {*
*  node (**Jenkins Agent (Devops)' {*
*    ...*
*  }*
*}*

then, each time the function is called, a new workspace is created, and I 
lose some vital state information that I need in the workspace directory. I 
guess if I replace my functions with closures, I can wrap them all in a 
single node, like this:

*node (**Jenkins Agent (Devops)' {*
*  def do_something1() {*
*   ...*
*  }*

*  def do_something2() {*
*   ...*
*  }*
*}*

However, I can't work out how to 'call' the closures from the original 
Jenkinsfile now. The same method of doing pipeline.do_something1() does not 
work. Jenkins throws an error "No such property: do_something1 for class: 
groovy.lang.Binding"

So... help! :)

Doug.


-- 
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/ab1d5489-de8e-4b99-821a-47619036ef7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to