diff --git a/src/main/java/jenkins/plugins/jobcacher/ArbitraryFileCache.java b/src/main/java/jenkins/plugins/jobcacher/ArbitraryFileCache.java index 09dfb3b..0a5524e 100644 --- a/src/main/java/jenkins/plugins/jobcacher/ArbitraryFileCache.java +++ b/src/main/java/jenkins/plugins/jobcacher/ArbitraryFileCache.java @@ -170,12 +170,13 @@ public String getTitle() { @Override public Saver cache(ObjectPath cachesRoot, ObjectPath fallbackCachesRoot, Run build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) throws IOException, InterruptedException { - FilePath resolvedPath = resolvePath(workspace, initialEnvironment); + String expandedPath = initialEnvironment.expand(path); + FilePath resolvedPath = workspace.child(expandedPath); ExistingCache existingCache = resolveExistingValidCache(cachesRoot, fallbackCachesRoot, workspace, listener); if (existingCache == null) { logMessage("Skip restoring cache as no up-to-date cache exists", listener); - return new SaverImpl(resolvedPath); + return new SaverImpl(expandedPath); } logMessage("Restoring cache...", listener); @@ -191,13 +192,7 @@ public Saver cache(ObjectPath cachesRoot, ObjectPath fallbackCachesRoot, Run includes = new ArrayList(); - List excludes = new ArrayList(); + List includes = new ArrayList<>(); + List excludes = new ArrayList<>(); for (String decidingFilePattern : cacheValidityDecidingFile.split(",")) { if (decidingFilePattern.startsWith("!")) { @@ -343,22 +338,23 @@ private class SaverImpl extends Saver { private static final long serialVersionUID = 1L; - private final FilePath resolvedPath; + private final String expandedPath; - public SaverImpl(FilePath resolvedPath) { - this.resolvedPath = resolvedPath; + public SaverImpl(String expandedPath) { + this.expandedPath = expandedPath; } @Override public long calculateSize(ObjectPath objectPath, Run build, FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException { - return resolvedPath.act(new DirectorySize(includes, excludes)); + return workspace.child(expandedPath).act(new DirectorySize(includes, excludes)); } @Override public void save(ObjectPath cachesRoot, Run build, FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException { + FilePath resolvedPath = workspace.child(expandedPath); if (!resolvedPath.exists()) { logMessage("Cannot create cache as the path does not exist", listener); - if (isPathOutsideWorkspace(workspace) && isMaybeInsideDockerContainer(workspace)) { + if (isPathOutsideWorkspace(resolvedPath, workspace) && isMaybeInsideDockerContainer(workspace)) { logMessage("Note that paths outside the workspace while using the Docker Pipeline plugin are not supported", listener); } return; @@ -395,7 +391,7 @@ public void save(ObjectPath cachesRoot, Run build, FilePath workspace, Lau } } - private boolean isPathOutsideWorkspace(FilePath workspace) { + private boolean isPathOutsideWorkspace(FilePath resolvedPath, FilePath workspace) { return !StringUtils.startsWith(resolvedPath.getRemote(), workspace.getRemote()); }