I need to perform some tasks if a particular command fails. More specifically need to check if a key exists in rundeck, if not create it else do nothing. I have following:
rd keys info -p keys/finance/password_a
if [ $? -ne 0 ]
then
rd keys create -p 'keys/finance/password_a' -t 'password' -f ~/rundeck/password_a
fi
rd
command exits in 0
if the key exists, or in an error code if it doesn't.
Issue is, this script is part of pipeline provisioning tasks which fails and exists as soon as any command in it fails. So, the execution never reaches the point if [ $? -ne 0 ]
and exits right at rd
command after emits and non-zero status code.
Is there a way I can detect a command's final status code but still somehow make it emit a success code i.e. 0
?