Reputation: 49
I have Jenkinsfile as below in Declarative Pipeline format.
pipeline{
agent{
label 'xyz-test'
}
options{
timeout(time: 1, unit: 'HOURS')
timestamps()
}
environment {
UTILITY = load pwd() + 'path to /utils.groovy'
}
stages{
stage('Build'){
steps{
sh "${UTILITY.functionX()}"
}
}
}
}
I have a groovy file with name utils.groovy
def functionX(){
}
def functionY(){
}
return this;
When I call functionX() in such a way, I am getting below error in the console.
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method
Upvotes: 1
Views: 7624
Reputation: 316
you need to use 'load' steps from 'Pipeline: Groovy' plugin (https://plugins.jenkins.io/workflow-cps) in a script block. (https://jenkins.io/doc/pipeline/steps/workflow-cps/#-load-evaluate-a-groovy-source-file-into-the-pipeline-script)
ex:
stages {
stage ("load scripts"){
steps {
script {
scripts=load "jenkins/scripts/loadScripts.groovy"
}
}
}
Upvotes: 1