From 7452486c72dcef795e719d13e569ee2e6b4dde17 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 6 Feb 2019 13:39:19 -0800 Subject: [PATCH] Kill running docker containers left over from a previous job --- .buildkite/hooks/post-checkout | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.buildkite/hooks/post-checkout b/.buildkite/hooks/post-checkout index b47ad6a50d..db20f41cc6 100644 --- a/.buildkite/hooks/post-checkout +++ b/.buildkite/hooks/post-checkout @@ -1,6 +1,21 @@ CI_BUILD_START=$(date +%s) export CI_BUILD_START +# +# Kill any running docker containers, which are potentially left over from the +# previous CI job +# +( + containers=$(docker ps -q) + if [[ -n $containers ]]; then + echo "Killing stale docker containers" + docker ps + + # shellcheck disable=SC2086 # Don't want to double quote $containers + docker kill $containers + fi +) + # Processes from previously aborted CI jobs seem to loiter, unclear why as one # would expect the buildkite-agent to clean up all child processes of the # aborted CI job.