I am trying to use jq to create a json from a template json file using --args and the template file. When I execute the below command, jq just hangs in there forever.
I am a rookie with jq, would really appreciate if someone can point out what am I doing wrong.
template.jq
{
"channel": "channel",
"attachments": [
{
"color": "#a7dbb5",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": $SUMMARY,
"emoji": true
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Build ID: * <\($BUILD_URL)|\($BUILD_ID)>\n*Duration:* \($DURATION)\n*User: *<\($USER_EMAIL)|\($USER_NAME)>\n*Test Cases:* \($TEST_CASES)"
},
"accessory": {
"type": "image",
"image_url": "https://raw.githubusercontent.com/sudas-px/dev-repo/main/check.png",
"alt_text": "status thumbnail"
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Portworx*\nv\($PX_VERSION)"
},
{
"type": "mrkdwn",
"text": "*PX Backup*\nv\($PX_BACKUP_VERSION)"
}
]
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Stork Image:*\n\($STORK_IMAGE)"
},
{
"type": "mrkdwn",
"text": "*Kubernetes:*\nv\($K8S_VERSION)"
}
]
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Github Repository*"
},
{
"type": "mrkdwn",
"text": $GITHUB_REPO
}
]
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Branch*"
},
{
"type": "mrkdwn",
"text": $GITHUB_BRANCH
}
]
},
{
"type": "divider"
},
{
"type": "actions",
"block_id": "actionblock789",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Pipeline"
},
"style": "primary",
"url": $BUILD_URL
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Logs"
},
"url": $KIBANA_URL
}
]
}
]
}
]
}
This is the command I ran
jq --arg SUMMARY "Summary" --arg BUILD_ID "BUILD_ID" --arg BUILD_URL "BUILD_URL" --arg DURATION "DURATION" --arg USER_EMAIL "EMAIL" --arg USER_NAME "USER" --arg TEST_CASES 3 --arg PX_VERSION "VERSION" --arg PX_BACKUP_VERSION "PX_VERSION" --arg STORK_IMAGE "IMAGE_STORK" --arg K8S_VERSION "1.23.0" --arg GITHUB_BRANCH "branch" --arg GITHUB_REPO "repo" --arg KIBANA_URL "url" -f template.jq
>Solution :
Your "template" is just a filter that requires no input, but you forgot to tell jq that the filter won’t need any input. As a result, jq is waiting to read from standard input. Use the -n option to tell jq it doesn’t need to read from standard input.
jq -n <lots of --args> -f template.jq