Something that you could do is this:
# Execute the first command and capture its output
output=$(qovery environment list --json | jq -r '.[] | select(.name == "$BRANCH_NAME")')
# Check if the output is empty
if [ -z "$output" ]; then
# The output is empty, so clone the environment
qovery environment clone \
--organization "x" \
--project "x" \
--environment "entity-store" \
--new-environment-name "$BRANCH_NAME"
else
echo "Environment 'Toto' found, no need to clone."
fi
Then you make sure you don’t skip any potential errors while cloning.