Resolved: Read YAML components from variable in groovy 0 By Isaac Tonny on 17/06/2022 Issue Share Facebook Twitter LinkedIn Question: I have a code like below import groovy.yaml.YamlSlurper def configYaml = '''\ --- application: "Sample App" users: - name: "mrhaki" likes: - Groovy - Clojure - Java - name: "Hubert" likes: - Apples - Bananas connections: - "WS1" - "WS2" ''' // Parse the YAML. def config = new YamlSlurper().parseText(configYaml) def data1 = "users" def date2 = "name" println config.users.likes // printing correct println config.$data1.$data2 // getting error I need to print elements from users.name and I need to print it from variable form. like “println config.$data1.$data2” Answer: You can do something like below. def config = new YamlSlurper().parseText(configYaml) def data1 = "users" def data2 = "name" println config.users.likes println config."$data1"."$data2" If you have better answer, please add a comment about this, thank you! groovy jenkins-groovy