I have a jenkins pipeline which load a groovy utility script like this :
Utils = load('/var/lib/jenkins/utils/Utils.groovy')
Everything is fine when I execute the pipeline on the master node. In this case I'm able to use the methods inside my class Utils in the pipeline.
node('master'){
stage('stage1'){
def Utils = load('/var/lib/jenkins/utils/Utils.groovy')
Utils.doSomething()
}
}
My problem came when I try to execute my pipeline in a slave. In this case the load above causes the error
java.io.IOException: java.io.FileNotFoundException: /var/lib/jenkins/utils/Utils.groovy (No such file or directory)
To avoid this error, in the pipeline, I load the file in master node like this
node('master'){
stage('stage1'){
Utils = load('/var/lib/jenkins/utils/Utils.groovy')
}
}
node(){
stage('stage2'){
Utils.doSomething()
}
}
This is not very efficient and I don't want to use the master just for loading the file Have you any advice on how to load a Groovy scipt on a slave node ?
Thank you