gitness
gitness copied to clipboard
Jsonnet nested template data
Overview
This PR provides ability to put nested YAML arrays and mappings as serialized JSON string values into jsonnet's vm.ExtVar
function and use it later in the jsonnet pipeline template with std.parseJson
.
Example pipeline:
kind: template
load: plugin.jsonnet
data:
stepName: my_step
image: my_image
commands: my_command
additionalSteps:
- name: my_second_step
image: my_second_image
commands:
- my_second_command1
- my_second_command2
- name: my_third_step
image: my_third_image
commands:
- my_third_command
Example jsonnet template:
local stepName = std.extVar("input.stepName");
local image = std.extVar("input.image");
local commands = std.extVar("input.commands");
local additionalSteps = std.parseJson(std.extVar("input.additionalSteps"));
{
"kind": "pipeline",
"type": "docker",
"name": "default",
"steps": [
{
"name": stepName,
"image": image,
"commands": [
commands
]
}
] + [step for step in additionalSteps]
}
Processed output:
---
{
"kind": "pipeline",
"name": "default",
"steps": [
{
"commands": [
"my_command"
],
"image": "my_image",
"name": "my_step"
},
{
"commands": [
"my_second_command1",
"my_second_command2"
],
"image": "my_second_image",
"name": "my_second_step"
},
{
"commands": [
"my_third_command"
],
"image": "my_third_image",
"name": "my_third_step"
}
],
"type": "docker"
}
Of course, the above examples seem a bit of a stretch and make the new functionalty look redundant, but those are for testing purposes only. With the power of jsonnet we can implement much more complex templating solutions for a broader set of use cases. I can try and work on the real-world example if you want.
This PR has been automatically closed due to inactivity.