From 4b5c535be9e3b6c8f35f4072395235aaeeed96e7 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Wed, 18 Sep 2019 21:47:58 +0000 Subject: [PATCH] Jenkinsfile: ensure all containers are cleaned up By convention, containers spawned by jenkins jobs have the name: docker-pr${BUILD_NUMBER} That works fine for jobs with a single container. This commit cleans up when multiple containers are spawned with the convention that their names share the same "docker-pr${BUILD_NUMBER}-" prefix. Signed-off-by: Tibor Vass (cherry picked from commit f470698c2c10c2382080fab34f83088450fabdd6) Signed-off-by: Andrew Hsu --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 4cd0521b58..6a5137e3fc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -662,6 +662,8 @@ pipeline { sh ''' echo "Ensuring container killed." docker rm -vf docker-pr$BUILD_NUMBER || true + cids=$(docker ps -aq -f name=docker-pr${BUILD_NUMBER}-*) + [ -n "$cids" ] && docker rm -vf $cids || true ''' sh '''