From: Thanh Ha Date: Tue, 5 Mar 2019 01:47:38 +0000 (-0500) Subject: Rework image code to handle no results from YAML X-Git-Tag: v0.33.0~5 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=399343540de75a62321e715057798a19d8054abf;p=releng%2Fglobal-jjb.git Rework image code to handle no results from YAML When grep has 0 matches it returns a non-zero exit code. In this case a 0 match grep is a possibility for YAML files so ignore grep's exit code in this instance. Change-Id: Ia7eb55364feeb42bf35681c4ae0798fe25bbfad1 Signed-off-by: Thanh Ha --- diff --git a/shell/openstack-protect-in-use-images.sh b/shell/openstack-protect-in-use-images.sh index 4d9a2cc8..fe0bc0f1 100644 --- a/shell/openstack-protect-in-use-images.sh +++ b/shell/openstack-protect-in-use-images.sh @@ -22,14 +22,15 @@ os_cloud="${OS_CLOUD:-vex}" set -eu -o pipefail declare -a images -declare -a cfg_images -declare -a yaml_images -readarray -t cfg_images <<< "$(grep -r IMAGE_NAME --include \*.cfg jenkins-config \ - | awk -F'=' '{print $2}' | sort -u)" -readarray -t yaml_images <<< "$(grep -r 'ZZCI - ' --include \*.yaml jjb \ +images+=("$(grep -r IMAGE_NAME --include \*.cfg jenkins-config \ + | awk -F'=' '{print $2}' | sort -u)") +set +o pipefail # Not all projects have images in YAML files and grep returns non-zero on 0 results +# Ignore SC2179 since we do not want () to result in an empty array item. +#shellcheck disable=SC2179 +images+="$(grep -r 'ZZCI - ' --include \*.yaml jjb \ | awk -F": " '{print $3}' | sed "s:'::;s:'$::;/^$/d" | sort -u)" -mapfile -t images < <(for R in "${cfg_images[@]}" "${yaml_images[@]}" ; do echo "$R" ; done | sort -u) - +set -o pipefail +readarray -t images <<< "$(for i in "${images[@]}"; do echo "$i"; done | sort)" for image in "${images[@]}"; do os_image_protected=$(openstack --os-cloud "$os_cloud" \