Operations 2 min read

Calling Other Groovy Files and All Groovy Files in a Directory from build.groovy – Example

This article explains how to invoke other Groovy scripts and all Groovy files within a directory from a build.groovy file, providing concrete example code that demonstrates calling a Print method in hello.groovy and using it inside mytools.groovy.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Calling Other Groovy Files and All Groovy Files in a Directory from build.groovy – Example

The problem asks how to define calls from build.groovy to other xxx.groovy files and to all xxx.groovy files in a directory, and requests a working example.

Below is an example where mytools.groovy calls the Print() method defined in hello.groovy:

package org.devops

def Print(){
    println("hello")
}

The calling script mytools.groovy creates an instance of the hello class and invokes its Print() method:

package org.devops

def sayHello(){
    def hello = new hello()
    hello.Print()
}
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Build AutomationDevOpsScriptingGroovyexample
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.