The jq command returns null when it can't find the asset which is then turned into 4 character string "null". Therefore the condition that should exit the script with 1 is never true because the string is not empty.
This can be verified on this example of empty assets array:
ASSET_ID=$(echo "{ \"assets\": [] }" | jq ".assets | map(select(.name == \"myasset.jar\"))[0].id")
if [[ -z "$ASSET_ID" ]]; then
echo "Could not find asset ID"
exit 1
fi
echo "Asset ID exists: $ASSET_ID"
exit 0
The script above will output Asset ID exists: null and exit with status 0.
The script has an error on this line https://github.com/dsaltares/fetch-gh-release-asset/blob/master/fetch_github_asset.sh#L48
The
jq
command returnsnull
when it can't find the asset which is then turned into 4 character string"null"
. Therefore the condition that should exit the script with1
is nevertrue
because the string is not empty.This can be verified on this example of empty
assets
array:The script above will output
Asset ID exists: null
and exit with status0
.