Skip to content

Instantly share code, notes, and snippets.

@atemate
Last active July 19, 2023 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atemate/c1a240523c4351ba994440658815e821 to your computer and use it in GitHub Desktop.
Save atemate/c1a240523c4351ba994440658815e821 to your computer and use it in GitHub Desktop.
export a variable from a json payload
set -eu
# shortcut for getting payload values
function export_payload_var() {
name="$1"
pattern="$2"
value=$(jq -r "$pattern" "${PAYLOAD}")
if [[ "$value" == "null" ]]; then
echo "Could not find pattern '$pattern' in payload '${PAYLOAD}'"
exit 1
fi
echo export "$name"="$value"
}
export_pipeline_var GCP_PROJECT '.data.project_id'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment