github-pr-resource
github-pr-resource copied to clipboard
load_var friendly format for metadata.json
The current output format for metadata.json
that gets populated on a get
step is a list of maps:
[{"name": "item1", "value": "bla"},
{"name": "item2", "value": "foo"},
...]
Instead, a simple map like {"item1": "bla", "item2": "foo"}
would be more useful for Concourse's load_var
step and then we wouldn't need a separate load_var
for every metadata file that gets dumped.
Currently, the metadata.json
is being populated with a list of maps:
[
{"name": "item1", "value": "bla"},
{"name": "item2", "value": "foo"},
...
]
To change this to a simple map structure like:
{
"item1": "bla",
"item2": "foo",
...
}
You'll need to modify the logic that generates the metadata.json
file in Concourse. Here's a high-level approach to achieve this:
-
Modify the Metadata Generation Logic: Locate the part of your Concourse pipeline or resource definition where the
metadata.json
is generated after aget
step. This is typically done in a custom script or resource script. -
Transform List of Maps to Map: Inside the script, after fetching the metadata, you'll need to transform the list of maps into the desired map structure. You can achieve this by iterating through the list of maps and constructing the new map:
# Fetch metadata.json content metadata_json=$(cat metadata.json) # Transform list of maps to map map_json="{}" for item in $(echo "$metadata_json" | jq -r '.[] | @base64'); do name=$(echo "$item" | base64 --decode | jq -r '.name') value=$(echo "$item" | base64 --decode | jq -r '.value') map_json=$(echo "$map_json" | jq --arg name "$name" --arg value "$value" '.[$name] = $value') done # Output the transformed map as JSON echo "$map_json" > transformed_metadata.json
-
Use the Transformed Metadata: The
transformed_metadata.json
file now contains the desired map structure. You can use this transformed metadata in your Concourse tasks or steps that rely on it.