diff --git a/.kokoro/build-with-appengine.sh b/.kokoro/build-with-appengine.sh index 90c6559608..2034649426 100755 --- a/.kokoro/build-with-appengine.sh +++ b/.kokoro/build-with-appengine.sh @@ -42,25 +42,21 @@ VERSION=$(echo $VERSION | sed 's_/flexible\|/standard__') export GAE_VERSION=$VERSION export GCLOUD_STORAGE_BUCKET=docs-samples-${VERSION} -# Register post-test cleanup -function cleanup { - gcloud app versions delete $GAE_VERSION --quiet -} -trap cleanup EXIT - - cd github/nodejs-docs-samples/${PROJECT} - # Configure gcloud export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/secrets-key.json gcloud auth activate-service-account --key-file "$GOOGLE_APPLICATION_CREDENTIALS" gcloud config set project $GCLOUD_PROJECT - # Deploy the app gcloud app deploy --version $GAE_VERSION --no-promote --quiet +# Register post-test cleanup +function cleanup { + gcloud app versions delete $GAE_VERSION --quiet +} +trap cleanup EXIT HUP # Install dependencies and run tests npm install @@ -69,11 +65,13 @@ npm install # to open issues on failures: if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"release"* ]]; then export MOCHA_REPORTER_SUITENAME=${PROJECT} - cleanup() { - chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop - $KOKORO_GFILE_DIR/linux_amd64/buildcop + notify_buildcop() { + # Call the original trap function. + cleanup + chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop + $KOKORO_GFILE_DIR/linux_amd64/buildcop } - trap cleanup EXIT HUP + trap notify_buildcop EXIT HUP fi npm test diff --git a/.kokoro/build-with-run.sh b/.kokoro/build-with-run.sh index 0e92d53179..7ede33d250 100755 --- a/.kokoro/build-with-run.sh +++ b/.kokoro/build-with-run.sh @@ -46,17 +46,17 @@ SUFFIX=${KOKORO_BUILD_ID} export SERVICE_NAME="${SAMPLE_NAME}-${SUFFIX}" export CONTAINER_IMAGE="gcr.io/${GOOGLE_CLOUD_PROJECT}/run-${SAMPLE_NAME}:${SAMPLE_VERSION}" -# Register post-test cleanup. -function cleanup { - gcloud --quiet container images delete "${CONTAINER_IMAGE}" || true -} -trap cleanup EXIT - # Build the service set -x gcloud builds submit --tag="${CONTAINER_IMAGE}" set +x +# Register post-test cleanup. +function cleanup { + gcloud --quiet container images delete "${CONTAINER_IMAGE}" || true +} +trap cleanup EXIT HUP + # Install dependencies and run Nodejs tests. export NODE_ENV=development npm install @@ -65,11 +65,13 @@ npm install # to open issues on failures: if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"release"* ]]; then export MOCHA_REPORTER_SUITENAME=${PROJECT} - cleanup() { - chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop - $KOKORO_GFILE_DIR/linux_amd64/buildcop + notify_buildcop() { + # Call the original trap function. + cleanup + chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop + $KOKORO_GFILE_DIR/linux_amd64/buildcop } - trap cleanup EXIT HUP + trap notify_buildcop EXIT HUP fi npm test