Repository navigation
fix(ci): ensure build.sh runs coerce_logs, flakybot, and teardown on failure - #15305
igorbernstein2 wants to merge 3 commits into
Conversation
…failure Fix latent set -eo pipefail early-exit bug in .kokoro/build.sh and .kokoro/common.sh where failing mvn invocations exited before RETURN_CODE=$?, coerce_logs.sh, or flakybot could run, while composing cleanly with setup_cloud() teardown.
There was a problem hiding this comment.
Code Review
This pull request refactors the Kokoro build scripts to ensure that post-build operations—such as log coercion, flakybot reporting, and cloud resource teardown—always execute on both successful and failed builds by introducing an EXIT trap (finalize_build). It also updates Maven command executions to capture exit codes instead of exiting immediately, and adds corresponding integration tests. The review feedback suggests guarding subsequent steps in .kokoro/build.sh if a prior Maven command fails, and registering the cleanup trap at the beginning of setup_cloud() in .kokoro/common.sh to prevent resource leaks if the setup itself fails.
…ove dead RETURN_CODE
| if [[ "${exit_code}" -eq 0 && "${REPORT_COVERAGE}" == "true" ]]; then | ||
| bash "${KOKORO_GFILE_DIR}/codecov.sh" | ||
| exit_code=$? | ||
| fi | ||
|
|
||
| # fix output location of logs | ||
| bash .kokoro/coerce_logs.sh || echo "Warning: coerce_logs.sh failed with exit code $?" >&2 | ||
|
|
||
| if [[ "${ENABLE_FLAKYBOT}" == "true" ]]; then | ||
| chmod +x "${KOKORO_GFILE_DIR}/linux_amd64/flakybot" && | ||
| "${KOKORO_GFILE_DIR}/linux_amd64/flakybot" -repo=googleapis/google-cloud-java || | ||
| echo "Warning: flakybot failed with exit code $?" >&2 | ||
| fi |
There was a problem hiding this comment.
CC: @jinseopkim0
do you have any thoughts on either codecov or flakybots as part of the CIs? I assume that we don't really have/ use either one of these right now. Doesn't seem like there is any harm in keep them as it seems like they need to be opt in via env vars.
lqiu96
left a comment
There was a problem hiding this comment.
LGTM. Thanks for finding this. I think we can proceed and we can do any follow up changes to either code cov/ flakybot in a follow up PR
Summary
Fixes a pre-existing
set -eo pipefailbug in.kokoro/build.shwhere failingmvninvocations exit immediately before running.kokoro/coerce_logs.shorflakybot.(Split out from #15301 so this bugfix can be reviewed independently of
CLEANUP_TARGET_DIRS.)Changes
codecov.sh(on passing builds whenREPORT_COVERAGE=true),coerce_logs.sh,flakybot(whenENABLE_FLAKYBOT=true), andsetup_cloud()teardown into anEXITtrap (finalize_build) in.kokoro/build.sh.set -efail-fast across allJOB_TYPEbranches (removing deadRETURN_CODEvariables) — bash passes the failing command's exit code directly intofinalize_build(local exit_code=$?).coerce_logs.sh/flakyboterrors so reporting hook failures never skip subsequent teardown or mask the build's exit code;codecov.shanddestroy_cloudfailures still fail passing builds (while preserving the original build exit code on failing builds).destroy_cloudinside( set -eo pipefail; destroy_cloud )as a standalone statement (not on the LHS of||) so Bash does not suppressset -einside.cloud/helpers/destroy.sh, anddestroy.sh'sset -eo pipefail/exitcalls cannot leak intofinalize_build.destroy_cloud()fromsetup_cloud()in.kokoro/common.sh(reusingcommonScriptDir) and gatetrap destroy EXITbehindSETUP_CLOUD_DEFER_TRAP=trueso.kokoro/build.sh'sEXITtrap is never clobbered bysetup_cloud(), while external callers (e.g.,sdk-platform-java/.kokoro/presubmit/downstream-build.sh) retain identical standaloneEXITtrap behavior.test_build_sh_failure_exit_pathin.kokoro/common_test.sh.Testing
bash -n .kokoro/common.sh .kokoro/build.sh .kokoro/common_test.shtest_build_sh_failure_exit_pathin.kokoro/common_test.shverifying:mvn verify(exit42) skipscodecov.sh, runscoerce_logs.shandflakybot(verifyingbuild.sh'schmod +x), and preserves exit42.mvn verify+ failingcodecov.sh(exit17) exits17while still runningcoerce_logs.shandflakybot.mvn verify(exit42) + failingcoerce_logs.shstill runsflakybotand preserves exit42.JOB_TYPE=integration+setup_cloud()with a realisticdestroy.sh(set -eo pipefail+ failing command + trailingpopd) logs the warning and preserves exit42on failing builds, and promotes exit9on passing builds instead of swallowing teardown failure as0.setup_cloud()underset -eo pipefail(aftercdinto a subdir) still runsdestroy.shand preserves exit3.