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?
In Jenkinsfile, simply use load step to load the Groovy script. After the Groovy script is loaded, the functions insides can be used where it can be referenced, as shown above.
In the example below, we are using Ubuntu 18.04. Note: The default location for the Jenkins configuration file on Ubuntu and Debian is /etc/default/jenkins. If you are working with RedHat, CentOS, or Fedora, the Jenkins configuration file is located at /etc/sysconfig/jenkins.
Using a shell script within Jenkins Pipeline can help simplify builds by combining multiple steps into a single stage. The shell script also allows users to add or update commands without having to modify each step or stage separately.
If anyone looking for yaml parser in jenkinsfile, I recommend the following
def yamlData = readYaml file: 'cae.yaml'
Reference : https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-readyaml-code-read-yaml-from-files-in-the-workspace-or-text
Try using the JsonSlurper:
def config = new JsonSlurper().parse(new File("config.json"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With