Last active
July 19, 2023 16:42
-
-
Save atemate/c1a240523c4351ba994440658815e821 to your computer and use it in GitHub Desktop.
export a variable from a json payload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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