Skip to content

Instantly share code, notes, and snippets.

@teodorescuserban
Last active October 30, 2018 10:11
Show Gist options
  • Save teodorescuserban/37818412b612cd3344d3d678fffe4c47 to your computer and use it in GitHub Desktop.
Save teodorescuserban/37818412b612cd3344d3d678fffe4c47 to your computer and use it in GitHub Desktop.
jenkins remove old docker image
# SERVICE is the docker-compose service name
OLD_IMAGE_ID=$(docker-compose images -q $SERVICE)
# CLEAN_UP_OLD_IMAGE is a jenkins boolean param
if [ "${CLEAN_UP_OLD_IMAGE}" == "true" ]; then
echo -en "\n\nTrying to remove the old image used for ${SERVICE} (ID: ${OLD_IMAGE_ID})...\n"
docker rmi ${OLD_IMAGE_ID} 2>/dev/null || echo -en "\nThis image is still in use and has NOT been removed.\n"
else
echo -en "\nThe old image remains on disk (ID: ${OLD_IMAGE_ID})...\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment