从 jenkins 管道 groovy 脚本加载配置文件的推荐方式

Recommended way of loading config file from jenkins pipeline groovy script

我想从 jenkins 管道脚本加载配置值(类似于 json、yaml、xml 或 ini)。当我尝试使用 org.yaml.snakeyaml.Yaml 我得到

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

我知道我可以解锁 org.yaml.snakeyaml.Yam,但消息告诉我这似乎不是加载配置文件的标准方式。

有没有办法加载已解锁的配置文件?

尝试使用 JsonSlurper:

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

如果有人在 jenkinsfile 中寻找 yaml 解析器,我推荐以下内容

 def yamlData = readYaml file: 'cae.yaml'

参考:https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-readyaml-code-read-yaml-from-files-in-the-workspace-or-text