Hi,
My Jenkinsfile is getting rather large and i want to break it down into
different groovy scripts for easy maintenance. Here is a sample code
structure.
externalScripts = ''
pipeline {
agent master
stages {
stage('first') {
agent { label 'master' }
steps {
script {
loadScripts()
externalScripts.functionA()
}
}
}
}
stage('second') {
agent { label 'some_slave_node' }
steps {
script {
externalScripts.functionB()
}
}
}
}
}
def someGlobalFunction() {
// some common code
}
def loadScripts() {
externalScripts = load 'script_next_to_jenkinsfile.groovy'
}
This works fine if i have some independent code defined in external groovy
file. But this breaks if i call a function defined in main Jenkinsfile.
// contents of script_next_to_jenkinsfile.groovy
def functionA() {
// Some regular code will work just fine
}
def functionB() {
// this throws an error - java.lang.NoSuchMethodError: No such DSL
method 'someGlobalFunction' found among steps....
someGlobalFunction()
}
return this
I thought the groovy files are loaded in the whole code. How can i make it
work like this setup ?
--
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/f959f630-2892-452b-a6da-2f56e3b8d329%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.