-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from jenkinsci/feature/docker-pipeline-plugin
Add additional hint if using paths outside workspace
- Loading branch information
Showing
6 changed files
with
242 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/main/java/jenkins/plugins/jobcacher/pipeline/CacheStepExecution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package jenkins.plugins.jobcacher.pipeline; | ||
|
||
import hudson.EnvVars; | ||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import jenkins.plugins.itemstorage.GlobalItemStorage; | ||
import jenkins.plugins.jobcacher.Cache; | ||
import jenkins.plugins.jobcacher.CacheManager; | ||
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback; | ||
import org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution; | ||
import org.jenkinsci.plugins.workflow.steps.StepContext; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class CacheStepExecution extends GeneralNonBlockingStepExecution { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final Long maxCacheSize; | ||
private final List<Cache> caches; | ||
private final String defaultBranch; | ||
|
||
protected CacheStepExecution(StepContext context, Long maxCacheSize, List<Cache> caches, String defaultBranch) { | ||
super(context); | ||
|
||
this.maxCacheSize = maxCacheSize; | ||
this.caches = caches; | ||
this.defaultBranch = defaultBranch; | ||
} | ||
|
||
@Override | ||
public boolean start() throws Exception { | ||
run(this::execute); | ||
return false; | ||
} | ||
|
||
private void execute() throws Exception { | ||
StepContext context = getContext(); | ||
|
||
Run<?, ?> run = context.get(Run.class); | ||
FilePath workspace = context.get(FilePath.class); | ||
Launcher launcher = context.get(Launcher.class); | ||
TaskListener listener = context.get(TaskListener.class); | ||
EnvVars initialEnvironment = context.get(EnvVars.class); | ||
|
||
List<Cache.Saver> cacheSavers = CacheManager.cache(GlobalItemStorage.get().getStorage(), run, workspace, launcher, listener, initialEnvironment, caches, defaultBranch); | ||
|
||
context.newBodyInvoker() | ||
.withContext(context) | ||
.withCallback(new ExecutionCallback(maxCacheSize, caches, cacheSavers)) | ||
.start(); | ||
} | ||
|
||
private static class ExecutionCallback extends BodyExecutionCallback { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final Long maxCacheSize; | ||
private final List<Cache> caches; | ||
private final List<Cache.Saver> cacheSavers; | ||
|
||
public ExecutionCallback(Long maxCacheSize, List<Cache> caches, List<Cache.Saver> cacheSavers) { | ||
this.maxCacheSize = maxCacheSize; | ||
this.caches = caches; | ||
this.cacheSavers = cacheSavers; | ||
} | ||
|
||
@Override | ||
public void onSuccess(StepContext context, Object result) { | ||
try { | ||
complete(context); | ||
|
||
context.onSuccess(result); | ||
} catch (Throwable t) { | ||
context.onFailure(t); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(StepContext context, Throwable t) { | ||
context.onFailure(t); | ||
} | ||
|
||
private void complete(StepContext context) throws IOException, InterruptedException { | ||
Run<?, ?> run = context.get(Run.class); | ||
FilePath workspace = context.get(FilePath.class); | ||
Launcher launcher = context.get(Launcher.class); | ||
TaskListener listener = context.get(TaskListener.class); | ||
|
||
CacheManager.save(GlobalItemStorage.get().getStorage(), run, workspace, launcher, listener, maxCacheSize, caches, cacheSavers); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.