using GroovyConsole I have file main.groovy with:
new Helpers().test("test method called")
and in the same dir have file Helpers.groovy with content
def test(String str) {
println "test method called with: " + str
}
Running results in results:
groovy> new Helpers().test("test method called")
test method called with: test method called
However, in the context of Jenkins using DSL, I have similar code, in file generator.groovy:
new Helpers().test("test method called")
then in Helpers.groovy in same dir I have:
def test(String str) {
println("test method called on: " + str)
}
However when I run I do not get any output (from the println) in the logs. If I have my def's in the same main.groovy file instead, it works fine.
Probably missing something fundamental. It's compiling / green in jenkins so not sure how to adapt this, so the runtime will do what I want.
You need to import class when call method from other files
Make a directory at the same level as the DSL called utilities and create a file called MyUtilities.groovy in the utilities directory with the following contents:
package utilities class MyUtilities { static void addMyFeature(def job) { job.with { description('Arbitrary feature') } } }
Then from the DSL, add something like this:
import utilities.MyUtilities
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With