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!