Operations 2 min read

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

This article explains how to invoke another Groovy script and all Groovy scripts in a directory from a build.groovy file, providing clear example code that demonstrates defining a method in one script and calling it from another within a DevOps automation context.

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

Problem: In a build.groovy script, the user wants to invoke other Groovy files (e.g., xxx.groovy) and all Groovy files in a directory, and asks for the proper definition and an example.

Solution: Provide two Groovy scripts – org.devops.hello.groovy defining a Print() method, and org.devops.mytools.groovy showing how to instantiate the hello class and call its Print() method from another script.

Code example for hello.groovy:

package org.devops

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

Code example for mytools.groovy:

package org.devops

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

The article notes that this content belongs to a DevOps engineering knowledge base and encourages readers to record related issues and contribute.

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 AutomationDevOpsScriptingGroovyJenkins
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.