speechmatics / artifactory-user-plugins

Sample Artifactory User Plugins
http://wiki.jfrog.org/confluence/display/RTF/User+Plugins
Apache License 2.0
0 stars 0 forks source link

add exception handling to cleanDockerImages #2

Open weakcamel opened 2 years ago

weakcamel commented 2 years ago

A bit of exception handling would be very helpful. As it is, if an exception is thrown in e.g.:

https://github.com/speechmatics/artifactory-user-plugins/blob/cab68586fc04f7820883cca5c37bbe08fec5cf8a/cleanup/cleanDockerImages/cleanDockerImages.groovy#L34

(which can happen for example when a repository from config file doesn't exist)

then nothing gets logged by Artifactory; this makes troubleshooting very difficult.

weakcamel commented 2 years ago

Example (could definitely be improved on):

diff --git a/cleanup/cleanDockerImages/cleanDockerImages.groovy b/cleanup/cleanDockerImages/cleanDockerImages.groovy
index 2e4e5ef..e724b50 100644
--- a/cleanup/cleanDockerImages/cleanDockerImages.groovy
+++ b/cleanup/cleanDockerImages/cleanDockerImages.groovy
@@ -38,7 +38,14 @@ executions {
         log.info("cleanDockerImages: Options dryRun=${dryRun}, byDownloadDate=${byDownloadDate}")
         repos.each {
             log.debug("Cleaning Docker images in repo: $it")
-            def del = buildParentRepoPaths(RepoPathFactory.create(it), dryRun, byDownloadDate)
+            def del
+           try {
+              del = buildParentRepoPaths(RepoPathFactory.create(it), dryRun, byDownloadDate)
+            } catch (Exception exc) {
+              log.debug("Building paths failed, details: ${exc}")
+             throw new RuntimeException(exc)
+           }
+            log.debug("Deleting the images now")
             deleted.addAll(del)
         }
         def json = [status: 'okay', dryRun: dryRun, deleted: deleted]