I am reading a YAML file using the Jenkins pipeline utility step readYaml
:
key1:
subkey1: val1
key2:
subkey2: val2
key2:
subkey2: val3
I noticed that the step is ignoring the duplicate keys in the YAML and throws no exception. When I looked into the source code I could not see any relevant configuration.
This plugin is using the snakeyaml
library. By default the snakeyaml
library allows duplicate keys as per the LoaderOptions
class.
If the Jenkins pipeline utility step is not changing the LoaderOptions
config then why the duplicate key is being ignored?
The YAML specification does not allow multiple keys.
The snakeyaml
loader option allowDuplicateKeys=true
means it will silently ignore any duplicate keys and not throw an exception.