Class BuildWrapper
- java.lang.Object
-
- hudson.model.AbstractDescribableImpl<BuildWrapper>
-
- hudson.tasks.BuildWrapper
-
- All Implemented Interfaces:
ExtensionPoint,Describable<BuildWrapper>
- Direct Known Subclasses:
SimpleBuildWrapper
public abstract class BuildWrapper extends AbstractDescribableImpl<BuildWrapper> implements ExtensionPoint
Pluggability point for performing pre/post actions for the build process.This extension point enables a plugin to set up / tear down additional services needed to perform a build, such as setting up local X display, or launching and stopping application servers for testing.
An instance of
BuildWrapperis associated with aProjectwith configuration information as its state. An instance is persisted along withProject.BuildWrappers are instantiated when the user saves the job configuration, and sticks around in memory until the job configuration is overwritten.The
setUp(Build,Launcher,BuildListener)method is invoked for each build.BuildWrapperrequires an user consent (in terms of a checkbox) to work. If this is not desirable, seeEnvironmentfor other ways to inject Environments to builds.- Author:
- Kohsuke Kawaguchi
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classBuildWrapper.EnvironmentRepresents the environment set up bysetUp(Build,Launcher,BuildListener).-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Constructor Summary
Constructors Constructor Description BuildWrapper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static DescriptorExtensionList<BuildWrapper,Descriptor<BuildWrapper>>all()Returns all the registeredBuildWrapperdescriptors.LauncherdecorateLauncher(AbstractBuild build, Launcher launcher, BuildListener listener)Provides an opportunity for aBuildWrapperto decorate aLauncherto be used in the build.OutputStreamdecorateLogger(AbstractBuild build, OutputStream logger)Provides an opportunity for aBuildWrapperto decorate theBuildListenerlogger to be used by the build.ActiongetProjectAction(AbstractProject job)Deprecated.UsegetProjectActions(AbstractProject)instead.Collection<? extends Action>getProjectActions(AbstractProject job)Actions to be displayed in the job page.voidmakeBuildVariables(AbstractBuild build, Map<String,String> variables)Called to define AbstractBuild.getBuildVariables().voidmakeSensitiveBuildVariables(AbstractBuild build, Set<String> sensitiveVariables)Called to define sensitive build variables.voidpreCheckout(AbstractBuild build, Launcher launcher, BuildListener listener)Provides an opportunity for aBuildWrapperto perform some actions before SCM checkout.BuildWrapper.EnvironmentsetUp(AbstractBuild build, Launcher launcher, BuildListener listener)Runs before theBuilderruns (but after the checkout has occurred), and performs a set up.BuildWrapper.EnvironmentsetUp(Build build, Launcher launcher, BuildListener listener)Deprecated.since 2007-10-28.-
Methods inherited from class hudson.model.AbstractDescribableImpl
getDescriptor
-
-
-
-
Method Detail
-
setUp
public BuildWrapper.Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException
Runs before theBuilderruns (but after the checkout has occurred), and performs a set up.- Parameters:
build- The build in progress for which anBuildWrapper.Environmentobject is created. Never null.launcher- This launcher can be used to launch processes for this build. If the build runs remotely, launcher will also run a job on that remote machine. Never null.listener- Can be used to send any message.- Returns:
- non-null if the build can continue, null if there was an error and the build needs to be aborted.
- Throws:
IOException- terminates the build abnormally. Jenkins will handle the exception and report a nice error message.UnsupportedOperationException- when a plugin does not support this type of build.InterruptedException- Since:
- 1.150
-
setUp
@Deprecated public BuildWrapper.Environment setUp(Build build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException
Deprecated.since 2007-10-28. UsesetUp(AbstractBuild, Launcher, BuildListener)instead.- Throws:
AbstractMethodError- when a plugin overrides neither this method norsetUp(AbstractBuild, Launcher, BuildListener).IOExceptionInterruptedException
-
decorateLauncher
public Launcher decorateLauncher(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException, Run.RunnerAbortedException
Provides an opportunity for aBuildWrapperto decorate aLauncherto be used in the build.This hook is called very early on in the build (even before
setUp(AbstractBuild, Launcher, BuildListener)is invoked.) The typical use ofLauncherdecoration involves in modifying the environment that processes run, such as the use of sudo/pfexec/chroot, or manipulating environment variables.The default implementation is no-op, which just returns the
launcherparameter as-is.- Parameters:
build- The build in progress for which thisBuildWrapperis called. Never null.launcher- The default launcher. Never null. This method is expected to wrap this launcher. This makes sure that when multipleBuildWrappers 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 thisLauncherand create an entirely differentLauncherand return it, too.listener- Connected to the build output. Never null. Can be used for error reporting.- Returns:
- Must not be null. If a fatal error happens, throw an exception.
- Throws:
Run.RunnerAbortedException- If a fatal error is detected but the implementation handled it gracefully, throw this exception to suppress stack trace.IOExceptionInterruptedException- Since:
- 1.280
- See Also:
LauncherDecorator
-
decorateLogger
public OutputStream decorateLogger(AbstractBuild build, OutputStream logger) throws IOException, InterruptedException, Run.RunnerAbortedException
Provides an opportunity for aBuildWrapperto decorate theBuildListenerlogger to be used by the build.This hook is called very early on in the build (even before
setUp(AbstractBuild, Launcher, BuildListener)is invoked.)The default implementation is no-op, which just returns the
loggerparameter as-is.(
ArgumentListBuilder.add(String, boolean)is a simpler way to suppress a single password.)- Parameters:
build- The build in progress for which thisBuildWrapperis called. Never null.logger- The default logger. Never null. This method is expected to wrap this logger. This makes sure that when multipleBuildWrappers attempt to decorate the same logger it will sort of work.- Returns:
- Must not be null. If a fatal error happens, throw an exception.
- Throws:
Run.RunnerAbortedException- If a fatal error is detected but the implementation handled it gracefully, throw this exception to suppress stack trace.IOExceptionInterruptedException- Since:
- 1.374
- See Also:
ConsoleLogFilter
-
preCheckout
public void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException
Provides an opportunity for aBuildWrapperto perform some actions before SCM checkout.This hook is called early on in the build (before
setUp(AbstractBuild, Launcher, BuildListener), but afterdecorateLauncher(AbstractBuild, Launcher, BuildListener)is invoked.) The typical use is delete existing workspace before new build starts etc.By the time this method is called, the workspace is assigned to the build, which can be obtained via
build.getWorkspace().The default implementation is no-op.
- Parameters:
build- The build in progress for which thisBuildWrapperis called. Never null.launcher- The launcher. Never null.listener- Connected to the build output. Never null. Can be used for error reporting.- Throws:
IOExceptionInterruptedException- Since:
- 1.399
-
getProjectAction
@Deprecated public Action getProjectAction(AbstractProject job)
Deprecated.UsegetProjectActions(AbstractProject)instead.Actionto be displayed in the job page.- Parameters:
job- This object owns theBuildWrapper. The returned action will be added to this object.- Returns:
- null if there's no such action.
- Since:
- 1.226
-
getProjectActions
public Collection<? extends Action> getProjectActions(AbstractProject job)
Actions to be displayed in the job page.- Parameters:
job- This object owns theBuildWrapper. The returned action will be added to this object.- Returns:
- can be empty but never null
- Since:
- 1.341
-
makeBuildVariables
public void makeBuildVariables(AbstractBuild build, Map<String,String> variables)
Called to define AbstractBuild.getBuildVariables(). This provides an opportunity for a BuildWrapper to append any additional build variables defined for the current build.- Parameters:
build- The build in progress for which thisBuildWrapperis called. Never null.variables- Contains existing build variables. Add additional build variables that you contribute to this map.
-
makeSensitiveBuildVariables
public void makeSensitiveBuildVariables(AbstractBuild build, Set<String> sensitiveVariables)
Called to define sensitive build variables. This provides an opportunity for a BuildWrapper to denote the names of variables that are sensitive in nature and should not be exposed in output.- Parameters:
build- The build in progress for which thisBuildWrapperis called. Never null.sensitiveVariables- Contains names of sensitive build variables. Names of sensitive variables that were added withmakeBuildVariables(hudson.model.AbstractBuild, java.util.Map)- Since:
- 1.378
-
all
public static DescriptorExtensionList<BuildWrapper,Descriptor<BuildWrapper>> all()
Returns all the registeredBuildWrapperdescriptors.
-
-