Skip to content

Instantly share code, notes, and snippets.

@minuz
Created June 28, 2024 04:14
Show Gist options
  • Select an option

  • Save minuz/aaca7424422f5b4a6726c006f0f6380d to your computer and use it in GitHub Desktop.

Select an option

Save minuz/aaca7424422f5b4a6726c006f0f6380d to your computer and use it in GitHub Desktop.
Replace Pipeline environment Variables
#!/bin/bash
# Initialize empty JSON object
json_object="{}"
# Loop through pipeline variables starting with VITE_
for var_name in "${!VITE@}"; do
# Check if variable starts with VITE_ (avoids unrelated variables)
if [[ $var_name =~ ^VITE_ ]]; then
# Extract variable value
var_value=${!var_name}
# Build JSON key-value pair directly using JQ
json_object=$(echo "$json_object" | jq '. + {"'"$var_name"'": "'"$var_value"'"}')
fi
done
# Save JSON object to file
echo "$json_object" > app-start/app.settings.json
echo "Successfully created app-start/app.settings.json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment