Created
January 11, 2022 11:12
-
-
Save MartinLuksik/5209eb367905e263462d0c2f0ded2a23 to your computer and use it in GitHub Desktop.
[Bash jq] Bash jq #jq #bash #linux
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
TOKEN=${1?Error: Must supply the token} | |
TF_OUTPUT_LOC=${2?Error: Must supply path to Terraform output file (json format)} | |
CON_ID=$(jq -rc '.service_connection_id' $TF_OUTPUT_LOC) | |
CON_NAME=$(jq -rc '.service_endpoint' $TF_OUTPUT_LOC) | |
PROJECT_NAME=$(jq -rc '.azdo_project' $TF_OUTPUT_LOC | sed 's/ /%20/g') #for url encoding | |
NAMESPACE=$(jq -rc '.namespace' $TF_OUTPUT_LOC) | |
CLUSTER=$(jq -rc '.cluster_name' $TF_OUTPUT_LOC) | |
APPR=$(jq -rc '.approvers' $TF_OUTPUT_LOC) | |
echo $CON_ID | |
echo $CON_NAME | |
echo $PROJECT_NAME | |
echo $NAMESPACE | |
echo $CLUSTER | |
echo $APPR |
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
# parse an json object "service_endpoints" from json | |
jq -rc '.service_endpoints.value' tf_output.json > service_endpoints.json | |
# [{"approvers":[],"azdo_project":"a","cluster_name":"a","namespace":"a","service_connection_id":"a","service_endpoint":"a"},{"approvers":[],"azdo_project":"b","cluster_name":"b","namespace":"b","service_connection_id":"b","service_endpoint":"b"}] | |
# itterate over the list of objects and for each echo it to a file and then execute a script while providing the path to the created file: | |
jq -c '.[]' service_endpoints.json | while read i; do echo $i > service_endpoint.json && ./create_env.sh $TOKEN service_endpoint.json; done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment