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('g...@scm.foobar.com: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.