Kill running docker containers left over from a previous job

This commit is contained in:
Michael Vines 2019-02-06 13:39:19 -08:00
parent afdf0efd31
commit 7452486c72
1 changed files with 15 additions and 0 deletions

View File

@ -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.