Skip to content

Commit 8c46fb0

Browse files
author
Jerjou Cheng
committed
Save the output of commands that error.
Also, revert inadvertent commit -_-;
1 parent 9cebf6c commit 8c46fb0

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

appengine/endpoints-frameworks-v2/discovery/jenkins.sh

100644100755
+4
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,27 @@ function TestEndpoints () {
2222
# Test getGreeting Endpoint (hello world!)
2323
curl -X GET \
2424
"https://${2}-dot-${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting/0" | \
25+
tee "$ERROR_OUTPUT_DIR/response.json" | \
2526
grep "hello version-${2}"
2627

2728
# Test getGreeting Endpoint (goodbye world!)
2829
curl -X GET \
2930
"https://${2}-dot-${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting/1" | \
31+
tee "$ERROR_OUTPUT_DIR/response.json" | \
3032
grep "goodbye world!"
3133

3234
# Test listGreeting Endpoint (hello world! and goodbye world!)
3335
curl -X GET \
3436
"https://${2}-dot-${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting" | \
37+
tee "$ERROR_OUTPUT_DIR/response.json" | \
3538
grep "hello world!\|goodbye world!"
3639

3740
# Test multiply Endpoint (This is a greeting.)
3841
curl -X POST \
3942
-H "Content-Type: application/json" \
4043
--data "{'message':'This is a greeting from instance ${2}'}." \
4144
"https://${2}-dot-${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting/1" | \
45+
tee "$ERROR_OUTPUT_DIR/response.json" | \
4246
grep "This is a greeting from instance ${2}."
4347
}
4448

appengine/endpoints-frameworks-v2/discovery/src/main/java/com/example/helloendpoints/Greetings.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Greetings {
4343
public static ArrayList<HelloGreeting> greetings = new ArrayList<HelloGreeting>();
4444

4545
static {
46-
greetings.add(new HelloGreeting("hello version-jerjou-test!"));
46+
greetings.add(new HelloGreeting("hello world!"));
4747
greetings.add(new HelloGreeting("goodbye world!"));
4848
}
4949
//[END api_def]

flexible/sparkjava/jenkins.sh

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set -xe
2121
function runtests () {
2222
curl -X GET \
2323
"https://${2}-dot-${1}.appspot.com/api/users" | \
24+
tee "$ERROR_OUTPUT_DIR/response.json" | \
2425
grep "^\\["
2526
}
2627

jenkins.sh

+27-12
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,58 @@ shopt -s globstar
1919
# We spin up some subprocesses. Don't kill them on hangup
2020
trap '' 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
2527
delete_app_version() {
2628
yes | gcloud --project="${GOOGLE_PROJECT_ID}" \
2729
app versions delete "${1}"
2830
}
31+
2932
handle_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
3954
shellcheck ./**/*.sh
4055

4156
# Find all jenkins.sh's and run them.
4257
find . -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

Comments
 (0)