Browse code

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 f470698c2c10c2382080fab34f83088450fabdd6)
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>

Tibor Vass authored on 2019/09/19 06:47:58
Showing 1 changed files
... ...
@@ -662,6 +662,8 @@ pipeline {
662 662
                             sh '''
663 663
                             echo "Ensuring container killed."
664 664
                             docker rm -vf docker-pr$BUILD_NUMBER || true
665
+                            cids=$(docker ps -aq -f name=docker-pr${BUILD_NUMBER}-*)
666
+                            [ -n "$cids" ] && docker rm -vf $cids || true
665 667
                             '''
666 668
 
667 669
                             sh '''