Writes yaml to a file in the current working directory or a String from an Object or a String. It uses SnakeYAML as YAML processor. The call will fail if the file already exists.
Fields:file
(optional):
Optional path to a file in the workspace to write the YAML datas to.
If provided, then returnText
must be false
or omitted.
It is required that either file
is provided, or returnText
is true
.
data
(optional):
An Optional Object containing the data to be serialized. You must specify data
or
datas
, but not both in the same invocation.
datas
(optional):
An Optional Collection containing the datas to be serialized as several YAML documents. You must specify
data
or datas
, but not both in the same invocation.
charset
(optional):
Optionally specify the charset to use when writing the file. Defaults to UTF-8
if nothing else is specified.
What charsets that are available depends on your Jenkins master system.
The java specification tells us though that at least the following should be available:
overwrite
(optional):
Allow existing files to be overwritten. Defaults to false
.
returnText
(optional):
Return the YAML as a string instead of writing it to a file. Defaults to false
.
If true
, then file
, charset
, and overwrite
must not be provided.
It is required that either file
is provided, or returnText
is true
.
Examples:
Writing to a file:
Writing to a string:
def amap = ['something': 'my datas',
'size': 3,
'isEmpty': false]
writeYaml file: 'datas.yaml', data: amap
def read = readYaml file: 'datas.yaml'
assert read.something == 'my datas'
assert read.size == 3
assert read.isEmpty == false
def amap = ['something': 'my datas',
'size': 3,
'isEmpty': false]
String yml = writeYaml returnText: true, data: amap
def read = readYaml text: yml
assert read.something == 'my datas'
assert read.size == 3
assert read.isEmpty == false