ci: address ShellCheck issues in deploy/jjb.sh

In ./deploy/jjb.sh line 11:
	oc get pod/${1} --no-headers -o=jsonpath='{.status.phase}'
                   ^--^ SC2086: Double quote to prevent globbing and word splitting.

In ./deploy/jjb.sh line 29:
cd $(dirname ${0})
^----------------^ SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
   ^-------------^ SC2046: Quote this to prevent word splitting.
             ^--^ SC2086: Double quote to prevent globbing and word splitting.

In ./deploy/jjb.sh line 31:
oc create -f jjb-${CMD}.yaml
                 ^----^ SC2086: Double quote to prevent globbing and word splitting.

In ./deploy/jjb.sh line 36:
	jjb_pod=$(oc get pods --no-headers -l job-name=jjb-${CMD} -o=jsonpath='{.items[0].metadata.name}')
                                                           ^----^ SC2086: Double quote to prevent globbing and word splitting.

In ./deploy/jjb.sh line 37:
	[ ${?} = 0 ] && [ -n "${jjb_pod}" ] && break
          ^--^ SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

In ./deploy/jjb.sh line 46:
	[ ${?} = 0 ] && ( [ "${status}" = "Succeeded" ] || [ "${status}" = "Failed" ] ) && break
          ^--^ SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
                        ^-- SC2235: Use { ..; } instead of (..) to avoid subshell overhead.

In ./deploy/jjb.sh line 54:
oc delete --wait -f jjb-${CMD}.yaml
                        ^----^ SC2086: Double quote to prevent globbing and word splitting.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-05-26 16:53:32 +02:00
parent f436143be1
commit 1cb2eef010

View File

@ -5,10 +5,13 @@
# container to report the status.
#
# error out in case a command fails
set -e
CMD="${1}"
get_pod_status() {
oc get pod/${1} --no-headers -o=jsonpath='{.status.phase}'
oc get "pod/${1}" --no-headers -o=jsonpath='{.status.phase}'
}
case "${CMD}" in
@ -23,18 +26,21 @@ case "${CMD}" in
esac
# make sure there is a valid OCP session
oc version || exit 1
oc version
# the deploy directory where this script is located, contains files we need
cd $(dirname ${0})
cd "$(dirname "${0}")"
oc create -f jjb-${CMD}.yaml
oc create -f "jjb-${CMD}.yaml"
# loop until pod is available
while true
do
jjb_pod=$(oc get pods --no-headers -l job-name=jjb-${CMD} -o=jsonpath='{.items[0].metadata.name}')
[ ${?} = 0 ] && [ -n "${jjb_pod}" ] && break
jjb_pod=$(oc get pods --no-headers -l "job-name=jjb-${CMD}" -o=jsonpath='{.items[0].metadata.name}')
ret=${?}
# break the loop when the command returned success and jjb_pod is not empty
[ ${ret} = 0 ] && [ -n "${jjb_pod}" ] && break
sleep 1
done
@ -42,8 +48,10 @@ done
while true
do
status=$(get_pod_status "${jjb_pod}")
ret=${?}
# TODO: is Running as a status sufficient, did it terminate yet?
[ ${?} = 0 ] && ( [ "${status}" = "Succeeded" ] || [ "${status}" = "Failed" ] ) && break
[ ${ret} = 0 ] && { [ "${status}" = "Succeeded" ] || [ "${status}" = "Failed" ]; } && break
sleep 0.5
done
@ -51,7 +59,7 @@ done
oc logs "${jjb_pod}"
# delete the job, so a next run can create it again
oc delete --wait -f jjb-${CMD}.yaml
oc delete --wait -f "jjb-${CMD}.yaml"
# return the exit status of the pod
[ "${status}" = 'Succeeded' ]