Nathan Nathan - 1 month ago 34
Groovy Question

Recommended way of loading config file from jenkins pipeline groovy script

I want to load a config value (something like json, yaml, xml or ini) from a jenkins pipeline script. When I try to use

org.yaml.snakeyaml.Yaml
I get


Scripts not permitted to use new org.yaml.snakeyaml.Yaml


I know I can unlock
org.yaml.snakeyaml.Yam
, but the message tells me that this does not seem to be the standard way of loading config files.

Is there a way of loading config files that is already unlocked?

Answer

Try using the JsonSlurper:

def config = new JsonSlurper().parse(new File("config.json"))
Comments