SnakeYaml, or why is writeYaml Limited?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

SnakeYaml, or why is writeYaml Limited?

George Sexton
I need to change a pod definition for Jenkins to be in YAML format so that I can add privileged.

I have a map already defined, if I can add one more attribute and convert it to yaml, it would be done. The problem is that writeYaml can't send the output to a text variable, and I can't write to a temp file because I don't have my pod defined yet.

First, why is writeYaml purposely limited to not output to a variable? readYaml can read from a text variable. I've run into other cases where I have to do an ugly hack of writing the output to a file, and then using readFile()

Does anyone have any examples of how to use the actual SnakeYaml library in Jenkins?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/405d667d-c5e7-4a52-a35c-67bf845d96bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: SnakeYaml, or why is writeYaml Limited?

Victor Martinez
Something like the below snippet should work:

import org.jenkinsci.plugins.pipeline.utility.steps.shaded.org.yaml.snakeyaml.Yaml

@NonCPS
def readYaml(data) {
  return (new Yaml()).dump(data)
}

println readYaml([name: "foo", surname: "bar", age: 1])

writeYaml implementation uses that particular Class and method:
- https://github.com/jenkinsci/pipeline-utility-steps-plugin/blob/59f3c669ca6125a10dd5e80907006b06903d7d04/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/conf/WriteYamlStep.java#L194

My 2 cents

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4ecacb54-8114-4a59-9946-ee84a66cec90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.