Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some shell errors. #550

Merged
merged 1 commit into from
Mar 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@

set -xe
shopt -s globstar
# We spin up some subprocesses. Don't kill them on hangup
trap '' HUP

app_version=""

# shellcheck disable=SC2120
delete_app_version() {
if [ -n "${app_version}" ] || [ $# -gt 0 ]; then
yes | gcloud --project="${GOOGLE_PROJECT_ID}" \
app versions delete "${1-${app_version}}"
fi
yes | gcloud --project="${GOOGLE_PROJECT_ID}" \
app versions delete "${1}"
}
handle_error() {
errcode=$? # Remember the error code so we can exit with it after cleanup

# Clean up
delete_app_version # shellcheck disable=SC2119
delete_app_version "$@"

exit ${errcode}
}
trap handle_error ERR

# First, style-check the shell scripts
shellcheck ./**/*.sh
Expand All @@ -45,16 +44,21 @@ find . -mindepth 2 -maxdepth 5 -name jenkins.sh -type f | while read -r path; do
# Use just the first letter of each subdir in version name
# shellcheck disable=SC2001
app_version="jenkins-$(echo "${dir#./}" | sed 's#\([a-z]\)[^/]*/#\1-#g')"

trap 'handle_error $app_version' ERR
(
# If there's an error, clean up

pushd "${dir}"
# Need different app versions because flex can't deploy over an existing
# version
GOOGLE_VERSION_ID="${app_version}" /bin/bash ./jenkins.sh
echo "Return code: $?"

# Clean up the app version in the background
nohup delete_app_version "${app_version}" &
delete_app_version "${app_version}" &
)
# Clear the trap
trap - ERR
done

wait