diff --git a/src/main/java/jenkins/plugins/jobcacher/ArbitraryFileCache.java b/src/main/java/jenkins/plugins/jobcacher/ArbitraryFileCache.java index f0f8c84..a2b8fae 100644 --- a/src/main/java/jenkins/plugins/jobcacher/ArbitraryFileCache.java +++ b/src/main/java/jenkins/plugins/jobcacher/ArbitraryFileCache.java @@ -179,12 +179,13 @@ public Saver cache(ObjectPath cachesRoot, ObjectPath fallbackCachesRoot, Run build, FilePath workspace, Lau logMessage("Creating cache...", listener); long cacheCreationStartTime = System.nanoTime(); - compressionMethod.getCacheStrategy().cache(resolvedPath, includes, excludes, useDefaultExcludes, cache, workspace); - if (isCacheValidityDecidingFileConfigured() && isOneCacheValidityDecidingFilePresent(workspace)) { - updateSkipCacheTriggerFileHash(cachesRoot, workspace); + + try { + compressionMethod.getCacheStrategy().cache(resolvedPath, includes, excludes, useDefaultExcludes, cache, workspace); + if (isCacheValidityDecidingFileConfigured() && isOneCacheValidityDecidingFilePresent(workspace)) { + updateSkipCacheTriggerFileHash(cachesRoot, workspace); + } + long cacheCreationEndTime = System.nanoTime(); + logMessage("Cache created in " + Duration.ofNanos(cacheCreationEndTime - cacheCreationStartTime).toMillis() + "ms", listener); + } catch (Exception e) { + logMessage("Failed to create cache", e, listener); } - long cacheCreationEndTime = System.nanoTime(); - logMessage("Cache created in " + Duration.ofNanos(cacheCreationEndTime - cacheCreationStartTime).toMillis() + "ms", listener); } private boolean isPathOutsideWorkspace(FilePath workspace) { @@ -393,6 +399,11 @@ private void updateSkipCacheTriggerFileHash(ObjectPath cachesRoot, FilePath work } } + private void logMessage(String message, Exception exception, TaskListener listener) { + logMessage(message, listener); + exception.printStackTrace(listener.getLogger()); + } + private void logMessage(String message, TaskListener listener) { String cacheIdentifier = path; if (getCacheName() != null) {