@@ -19,43 +19,58 @@ shopt -s globstar
1919# We spin up some subprocesses. Don't kill them on hangup
2020trap ' ' HUP
2121
22- app_version=" "
22+ # Temporary directory to store any output to display on error
23+ export ERROR_OUTPUT_DIR
24+ ERROR_OUTPUT_DIR=" $( mktemp -d) "
25+ trap ' rm -r "${ERROR_OUTPUT_DIR}"' EXIT
2326
24- # shellcheck disable=SC2120
2527delete_app_version () {
2628 yes | gcloud --project=" ${GOOGLE_PROJECT_ID} " \
2729 app versions delete " ${1} "
2830}
31+
2932handle_error () {
3033 errcode=$? # Remember the error code so we can exit with it after cleanup
3134
32- # Clean up
33- delete_app_version " $@ "
35+ # Clean up remote app version
36+ delete_app_version " ${1} " &
37+
38+ # Display any errors
39+ if [ -n " $( find " ${2} " -mindepth 1 -print -quit) " ]; then
40+ cat " ${2:? } " /* 1>&2
41+ fi
42+
43+ wait
3444
3545 exit ${errcode}
3646}
3747
48+ cleanup () {
49+ delete_app_version " ${GOOGLE_VERSION_ID} " &
50+ rm -r " ${ERROR_OUTPUT_DIR:? } /" *
51+ }
52+
3853# First, style-check the shell scripts
3954shellcheck ./** /* .sh
4055
4156# Find all jenkins.sh's and run them.
4257find . -mindepth 2 -maxdepth 5 -name jenkins.sh -type f | while read -r path; do
4358 dir=" ${path%/ jenkins.sh} "
44- # Use just the first letter of each subdir in version name
59+ # Need different app versions because flex can't deploy over an existing
60+ # version. Use just the first letter of each subdir in version name
61+ export GOOGLE_VERSION_ID
4562 # shellcheck disable=SC2001
46- app_version =" jenkins-$( echo " ${dir# ./ } " | sed ' s#\([a-z]\)[^/]*/#\1-#g' ) "
63+ GOOGLE_VERSION_ID =" jenkins-$( echo " ${dir# ./ } " | sed ' s#\([a-z]\)[^/]*/#\1-#g' ) "
4764
48- trap ' handle_error $app_version ' ERR
65+ trap ' handle_error "${GOOGLE_VERSION_ID}" "${ERROR_OUTPUT_DIR}" ' ERR
4966 (
5067 # If there's an error, clean up
5168
5269 pushd " ${dir} "
53- # Need different app versions because flex can't deploy over an existing
54- # version
55- GOOGLE_VERSION_ID=" ${app_version} " /bin/bash ./jenkins.sh
70+ /bin/bash ./jenkins.sh
5671
57- # Clean up the app version in the background
58- delete_app_version " ${app_version} " &
72+ # Clean up the app version
73+ cleanup
5974 )
6075 # Clear the trap
6176 trap - ERR
0 commit comments