From af1a4a2036f93f4b26d71a18a307d4e2d30fb143 Mon Sep 17 00:00:00 2001 From: Vojtech Juranek Date: Sat, 12 Feb 2011 22:36:22 +0100 Subject: [PATCH] Added pre-checkout method. This method is called after assinging the workspace to the build, but before SCM checkout. Can be implemented by BuildWrappers. --- .../main/java/hudson/model/AbstractBuild.java | 20 +++++++++++++++++ .../main/java/hudson/tasks/BuildWrapper.java | 22 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index cdc6adc2f7..4177e1227b 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -412,6 +412,7 @@ public abstract class AbstractBuild

,R extends Abs workspace = lease.path.getRemote(); node.getFileSystemProvisioner().prepareWorkspace(AbstractBuild.this,lease.path,listener); + preCheckout(launcher,listener); checkout(listener); if (!preBuild(listener,project.getProperties())) @@ -489,6 +490,25 @@ public abstract class AbstractBuild

,R extends Abs return l; } + + /** + * Run preCheckout on {@link BuildWrapper}s + * + * @param launcher + * The launcher, never null. + * @param listener + * Never null, connected to the main build output. + * @throws IOException + * @throws InterruptedException + */ + private void preCheckout(Launcher launcher, BuildListener listener) throws IOException, InterruptedException{ + if (project instanceof BuildableItemWithBuildWrappers) { + BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project; + for (BuildWrapper bw : biwbw.getBuildWrappersList()) + bw.preCheckout(AbstractBuild.this,launcher,listener); + } + } + private void checkout(BuildListener listener) throws Exception { try { for (int retryCount=project.getScmCheckoutRetryCount(); ; retryCount--) { diff --git a/core/src/main/java/hudson/tasks/BuildWrapper.java b/core/src/main/java/hudson/tasks/BuildWrapper.java index 9a791d95c0..0be4b9d9a6 100644 --- a/core/src/main/java/hudson/tasks/BuildWrapper.java +++ b/core/src/main/java/hudson/tasks/BuildWrapper.java @@ -201,6 +201,28 @@ public abstract class BuildWrapper extends AbstractDescribableImpl return logger; } + /** + * Provides an opportunity for a {@link BuildWrapper} to perform some actions before SCM checkout. + * + *

+ * This hook is called early on in the build (before {@link #setUp(AbstractBuild, Launcher, BuildListener)}, + * but after {@link #decorateLauncher(AbstractBuild, Launcher, BuildListener)} is invoked.) + * The typical use is delete existing workspace before new build starts etc. + * + *

+ * The default implementation is no-op. + * + * @param build + * The build in progress for which this {@link BuildWrapper} is called. Never null. + * @param launcher + * The launcher. Never null. + * @param listener + * Connected to the build output. Never null. Can be used for error reporting. + * + */ + public void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException{ + } + /** * {@link Action} to be displayed in the job page. * -- GitLab