Hi

   I'm testing out use of shared libraries by trying to expand on some of 
the sample code 
from https://jenkins.io/doc/book/pipeline/shared-libraries/. I created the 
'sayHello' step and thought I'd try to call that step from a class with the 
goal of being able to provide pre-packaged pipelines in the form of a 
class, with the flexibility of using the steps directly if necessary. I've 
tried multiple variations of the 'execute' method in HelloWorldPipeline, 
but can't seem to figure out how to reference the 'sayHello' step. 
Compounding my confusion is the error message I get seems to indicate that 
'sayHello' is in fact present in globals:

[Pipeline] End of Pipelinejava.lang.NoSuchMethodError: No such DSL method 
'sayHello' found among steps [ArtifactoryGradleBuild,..., zip] or symbols 
[all,..., zip] or globals [Artifactory, currentBuild, docker, env, params, 
pipeline, *sayHello*, scm]

at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:149)
        at 
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)...


The file structure and code that I'm using follows. Any help would be greatly 
appreciated! 


   Thanks!


   --- Chris


(project root)
+- src                 
|   +- test
|       +- HelloWorldPipeline.groovy // calls
+- vars
|   +- sayHello.groovy


// vars/sayHello.groovy

def call(String name = 'human') {
    echo "Hello, ${name}."
}


// src/test/HelloWorldPipeline
package test


class HelloWorldPipeline implements Serializable {
    
    def script
    def name
    
    HelloWorldPipeline(def script, def name) {
        this.script = script
        this.name = name
    }
    
    def execute() {
        this.script.sayHello this.name
        // script.sayHello() // - same error
        // sayHello("test")  // - same error
    }    
}


// Jenkinsfile
new test.HelloWorldPipeline(steps, 'user').execute();




-- 
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/67afb6c0-7404-485b-a8d4-37cc23fc7c36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to