I’m trying to use conditional logic for Helm package manager, ie. if the release is installed then helm should not install the same release, if not installed then helm should install it. So very basic conditional logic. My question though is not about Helm but rather bash scripting.
To check if Helm release is installed I’m using:
RELEASE_INSTALLED=$(helm status RELEASE_NAME -o json | jq -r ".info.status")
When it is installed then I’m getting string value deployed defined in RELEASE_INSTALLED variable. But when it is not then my bash script exits with error code 1. I would like my script to continue executing instead of immediately exiting. Then I could build some conditional logic if basically the command above fails. How can I do that having these settings at the beginning of the script?
set -o errexit
set -o pipefail
>Solution :
You can use a conditional expression.
RELEASE_INSTALLED=$(helm status RELEASE_NAME -o json | jq -r ".info.status" || echo 'not deployed')
errexit and pipefail don’t apply if the failing command is part of a conditional expression.