jenkins.io icon indicating copy to clipboard operation
jenkins.io copied to clipboard

Explain options for generating JSON to be used later in Pipeline

Open StackScribe opened this issue 3 years ago • 0 comments
trafficstars

Posted on gitter 15 Feb 2022: I want to know what is the best way to generate JSON file that will be used later in the pipeline (1. Parse Json file, replace fields with params from the pipeline, validate with JSON schema) ? The only way is to create a custom Groovy function and use it or is there another way to do this properly ?

I used to develop Groovy class bu maybe it is not useful in this case. If your tools allow to validate against json schema and replace vars easily it can be a good solution.

@halkeye responded: best is always hard to say.

  • You can use readJSON and writeJSON pipeline helpers, but that couples your logic very much into jenkins.
  • You can use the jq shell tool, which is super super powerful.
  • If your just trying to replace some strings, you can use envsubst / subst in bash really easily.

whats easiest to maintain is more about you and your use case. I prefer things in external processses so they can be tested/developed/maintained outside of jenkins

groovy code (in pipeline, using groovy() or sh("groovy") is fine) runs on the controller and not the agent, and is generally a smell.

StackScribe avatar Feb 16 '22 12:02 StackScribe