-
-
Save w3aran/4850e647c7ad92b939eab8ec909cb179 to your computer and use it in GitHub Desktop.
Jenkins pipeline script for Docker cleanup (remove dangling images and exited containers) in a given build agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node("${params.BUILD_AGENT}") { | |
stage('Dangling Containers') { | |
sh 'docker ps -q -f status=exited | xargs --no-run-if-empty docker rm' | |
} | |
stage('Dangling Images') { | |
sh 'docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi' | |
} | |
stage('Dangling Volumes') { | |
sh 'docker volume ls -qf dangling=true | xargs -r docker volume rm' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment