提交 1c79e35c 编写于 作者: K kohsuke

Added a hook to manipulate Launcher used during a build.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14938 71c3de6d-444a-0410-be80-ed276b4c234a
上级 6c33e025
......@@ -215,7 +215,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
protected abstract class AbstractRunner implements Runner {
/**
* Since configuration can be changed while a build is in progress,
* stick to one launcher and use it.
* create a launcher once and stick to it for the entire build duration.
*/
protected Launcher launcher;
......@@ -232,7 +232,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
builtOn = node.getNodeName();
hudsonVersion = Hudson.VERSION;
launcher = node.createLauncher(listener);
launcher = createLauncher(listener);
if(node instanceof Slave)
listener.getLogger().println(Messages.AbstractBuild_BuildingRemotely(node.getNodeName()));
......@@ -258,6 +258,17 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
return result;
}
/**
* Creates a {@link Launcher} that this build will use. This can be overridden by derived types
* to decorate the resulting {@link Launcher}.
*
* @param listener
* Always non-null. Connected to the main build output.
*/
protected Launcher createLauncher(BuildListener listener) throws IOException, InterruptedException {
return getCurrentNode().createLauncher(listener);
}
private void createSymLink(BuildListener listener, String name) throws InterruptedException {
Util.createSymlink(getProject().getBuildDir(),"builds/"+getId(),"../"+name,listener);
}
......
......@@ -6,6 +6,7 @@ import hudson.tasks.BuildWrapper.Environment;
import hudson.tasks.Builder;
import hudson.tasks.BuildTrigger;
import hudson.triggers.SCMTrigger;
import hudson.Launcher;
import java.io.File;
import java.io.IOException;
......@@ -128,6 +129,19 @@ public abstract class Build <P extends Project<P,B>,B extends Build<P,B>>
return null;
}
/**
* Decorates the {@link Launcher}
*/
@Override
protected Launcher createLauncher(BuildListener listener) throws IOException, InterruptedException {
Launcher l = super.createLauncher(listener);
for(BuildWrapper bw : project.getBuildWrappers().values())
l = bw.decorateLauncher(Build.this,l,listener);
return l;
}
public void post2(BuildListener listener) throws IOException, InterruptedException {
performAllBuildStep(listener, project.getPublishers(),true);
performAllBuildStep(listener, project.getProperties(),true);
......
......@@ -9,6 +9,7 @@ import hudson.model.Describable;
import hudson.model.Project;
import hudson.model.Action;
import hudson.model.AbstractProject;
import hudson.model.Run.RunnerAbortedException;
import java.io.IOException;
import java.util.Map;
......@@ -136,6 +137,38 @@ public abstract class BuildWrapper implements ExtensionPoint, Describable<BuildW
throw new UnsupportedOperationException(getClass()+" needs to implement the setUp method");
}
/**
* Provides an opportunity for a {@link BuildWrapper} to decorate a {@link Launcher} to be used in the build.
*
* <p>
* This hook is called very early on in the build (even before {@link #setUp(AbstractBuild, Launcher, BuildListener)} is invoked.)
* The typical use of {@link Launcher} decoration involves in modifying the environment that processes run,
* such as the use of sudo/pfexec/chroot, or manipulating environment variables.
*
* <p>
* The default implementation is no-op, which just returns the {@code listener} parameter as-is.
*
* @param build
* The build in progress for which this {@link BuildWrapper} is called. Never null.
* @param launcher
* The default launcher. Never null. This method is expected to wrap this launcher.
* This makes sure that when multiple {@link BuildWrapper}s attempt to decorate the same launcher
* it will sort of work. But if you are developing a plugin where such collision is not a concern,
* you can also simply discard this {@link Launcher} and create an entirely different {@link Launcher}
* and return it, too.
* @param listener
* Connected to the build output. Never null. Can be used for error reporting.
* @return
* Must not be null. If a fatal error happens, throw an exception.
* @throws RunnerAbortedException
* If a fatal error is detected but the implementation handled it gracefully, throw this exception
* to suppress stack trace.
* @since 1.280
*/
public Launcher decorateLauncher(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException, RunnerAbortedException {
return launcher;
}
/**
* {@link Action} to be displayed in the job page.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册