private void invokeCleanup(DockerClient client, List<String> builtImages, @Nonnull Set<String> containers) {
        PrintStream llog = taskListener.getLogger();

        if (cleanupDangling) {
            for (String containerId : containers) {
                try {
                    client.removeImageCmd(containerId)
                            .exec();
                    llog.printf("Removed dangling layer image %s.%n", containerId);
                    LOG.debug("Removed dangling layer image '{}'", containerId);
                } catch (NotFoundException | ConflictException ex) {
                    // ignore
                } catch (Throwable ex) {
                    taskListener.error("Can't remove dangling layer image " + containerId + ".");
                    LOG.error("Can't remove dangling layer image " + containerId, ex);
                }
            }
        }

        if (!cleanup) {
            llog.println("Skipping cleanup.");
            return;
        } else {
            llog.println("Running cleanup...");
        }

        for (String image : builtImages) {
            if (isNotEmpty(image)) {
                llog.println("Removing built image " + image);
                try {
                    client.removeImageCmd(image)
                            .exec();
                } catch (NotFoundException ex) {
                    llog.println("Image doesn't exist.");
                } catch (Throwable ex) {
                    taskListener.error("Can't remove image" + ex.getMessage());
                    //ignore as it cleanup
                }
            }
        }
    }
private void invokeCleanup ( DockerClient client , List < String > builtImages , @ Nonnull Set < String > containers ) { PrintStream llog = taskListener . getLogger ( ) ; if ( cleanupDangling ) { for ( String containerId : containers ) { try { client . removeImageCmd ( containerId ) . exec ( ) ; llog . printf ( "Removed dangling layer image %s.%n" , containerId ) ; LOG . debug ( "Removed dangling layer image '{}'" , containerId ) ; } catch ( NotFoundException | ConflictException ex ) { } catch ( Throwable ex ) { taskListener . error ( "Can't remove dangling layer image " + containerId + "." ) ; LOG . error ( "Can't remove dangling layer image " + containerId , ex ) ; } } } if ( ! cleanup ) { llog . println ( "Skipping cleanup." ) ; return ; } else { llog . println ( "Running cleanup..." ) ; } for ( String image : builtImages ) { if ( isNotEmpty ( image ) ) { llog . println ( "Removing built image " + image ) ; try { client . removeImageCmd ( image ) . exec ( ) ; } catch ( NotFoundException ex ) { llog . println ( "Image doesn't exist." ) ; } catch ( Throwable ex ) { taskListener . error ( "Can't remove image" + ex . getMessage ( ) ) ; } } } }
Try to clean as much as we can without throwing errors.