Calling global /vars from /src

43 views
Skip to first unread message

amir....@verizon.com

unread,
Aug 10, 2018, 12:30:49 PM8/10/18
to Jenkins Users

Situation is simple - 

IN A GLOBAL LIBRARY (OUTSIDE THE SANDBOX):

in src - a.b.c.Utils.groovy

in vars - Defaults.groovy


How do I call Defaults.groovy from within Utils.groovy?

In src:

#!groovy
package a.b.c

public class Utils implements Serializable {
    def script
    public def run() {
         script.echo(Defaults.text)
//groovy.lang.MissingPropertyException: No such property: Defaults for class: a.b.c.Utils
    }
}

in vars

#!groovy
public class Defaults {
    public static def text = "hello world"
}

in Jenkinsfile:

@Library("ItLoads")
utils = new a.b.c.Utils(this)
...
    utils.run()

so I tried to load the library explicitly

#!groovy
package a.b.c

public class Utils implements Serializable {
    def script
    public def run() {
         println(script.library("ItLoads").Defaults.text)
//Only using first definition of library pipelineUtilities
//java.lang.IllegalAccessException: Defaults was defined in file:///apps/opt/.../vars/Ansible.groovy which was not inside file:///apps/opt/.../src/
    }
}

So, Defaults is defined somewhere, but I have no idea how to get to it...

If I try to use Defaults in the Jenkinsfile, it works


Help!

Reply all
Reply to author
Forward
0 new messages