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 <tibor@docker.com>
(cherry picked from commit f470698c2c)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
This commit is contained in:
Tibor Vass 2019-09-18 21:47:58 +00:00 committed by Andrew Hsu
parent 80727e5a92
commit 4b5c535be9

2
Jenkinsfile vendored
View file

@ -662,6 +662,8 @@ pipeline {
sh ''' sh '''
echo "Ensuring container killed." echo "Ensuring container killed."
docker rm -vf docker-pr$BUILD_NUMBER || true 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 ''' sh '''