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

Save the output of commands that error. #561

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions appengine/endpoints-frameworks-v2/discovery/jenkins.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,27 @@ function TestEndpoints () {
# Test getGreeting Endpoint (hello world!)
curl -X GET \
"https://${2}-dot-${1}.appspot.com/_ah/api/helloworld/v1/hellogreeting/0" | \
tee "$ERROR_OUTPUT_DIR/response.json" | \
grep "hello version-${2}"

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Greetings {
public static ArrayList<HelloGreeting> greetings = new ArrayList<HelloGreeting>();

static {
greetings.add(new HelloGreeting("hello version-jerjou-test!"));
greetings.add(new HelloGreeting("hello world!"));
greetings.add(new HelloGreeting("goodbye world!"));
}
//[END api_def]
Expand Down
1 change: 1 addition & 0 deletions flexible/sparkjava/jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set -xe
function runtests () {
curl -X GET \
"https://${2}-dot-${1}.appspot.com/api/users" | \
tee "$ERROR_OUTPUT_DIR/response.json" | \
grep "^\\["
}

Expand Down
39 changes: 27 additions & 12 deletions jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,58 @@ shopt -s globstar
# We spin up some subprocesses. Don't kill them on hangup
trap '' HUP

app_version=""
# Temporary directory to store any output to display on error
export ERROR_OUTPUT_DIR
ERROR_OUTPUT_DIR="$(mktemp -d)"
trap 'rm -r "${ERROR_OUTPUT_DIR}"' EXIT

# shellcheck disable=SC2120
delete_app_version() {
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 "$@"
# Clean up remote app version
delete_app_version "${1}" &

# Display any errors
if [ -n "$(find "${2}" -mindepth 1 -print -quit)" ]; then
cat "${2:?}"/* 1>&2
fi

wait

exit ${errcode}
}

cleanup() {
delete_app_version "${GOOGLE_VERSION_ID}" &
rm -r "${ERROR_OUTPUT_DIR:?}/"*
}

# First, style-check the shell scripts
shellcheck ./**/*.sh

# Find all jenkins.sh's and run them.
find . -mindepth 2 -maxdepth 5 -name jenkins.sh -type f | while read -r path; do
dir="${path%/jenkins.sh}"
# Use just the first letter of each subdir in version name
# Need different app versions because flex can't deploy over an existing
# version. Use just the first letter of each subdir in version name
export GOOGLE_VERSION_ID
# shellcheck disable=SC2001
app_version="jenkins-$(echo "${dir#./}" | sed 's#\([a-z]\)[^/]*/#\1-#g')"
GOOGLE_VERSION_ID="jenkins-$(echo "${dir#./}" | sed 's#\([a-z]\)[^/]*/#\1-#g')"

trap 'handle_error $app_version' ERR
trap 'handle_error "${GOOGLE_VERSION_ID}" "${ERROR_OUTPUT_DIR}"' 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
/bin/bash ./jenkins.sh

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