'Jenkins pipeline vars not a singleton (to be used as groovy global config object)

Aren't jenkins libraries' vars-files supposed to be singletons? I wanted to use them as global configuration but I get this:

vars/myconfig.groovy

class myconfig{
  def configfoo
}

A.groovy

B.readconfig()
println "myconfig after loading configuration: " + myconfig

B.groovy

def readconfig()
{
println "myconfig  before parsing yml file: " + myconfig
configYaml = readFile("file": configfilePath)
Yaml parser = new Yaml()
myconfig = parser.load(configYaml )
println "myconfig after parsing yml file: " + myconfig
}

Console output

B.groovy myconfig before parsing yml file: myconfig @50b45f2c
B.groovy myconfig after parsing yml file: [configfoo:bar]
A.groovy myconfig after loading configuration: myconfig @4ff116c0


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source