Class SimpleBuildWrapper
- All Implemented Interfaces:
ExtensionPoint
,Describable<BuildWrapper>
BuildWrapper
that, like SimpleBuildStep
, may be called at various points within a build.
Such a build wrapper would typically be written according to make few assumptions about how it is being used. Some hints about this refactoring:
- Replace
AbstractBuild.getWorkspace()
with the provided path. - Replace
AbstractBuild.getProject()
withRun.getParent()
. - Use
FilePath.toComputer()
rather thanComputer.currentComputer()
. - Do not bother with
AbstractBuild.getBuildVariables()
if you are not passed anAbstractBuild
(treat it like an empty map). - The
SimpleBuildWrapper.Disposer
must be safely serializable. This means it should be astatic
class if nested, and define aserialVersionUID
.
- Since:
- 1.599
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Parameter passed tosetUp(jenkins.tasks.SimpleBuildWrapper.Context, hudson.model.Run<?, ?>, hudson.FilePath, hudson.Launcher, hudson.model.TaskListener, hudson.EnvVars)
to allow an implementation to specify its behavior after the initial setup.static class
An optional callback to run at the end of the wrapped block.Nested classes/interfaces inherited from class hudson.tasks.BuildWrapper
BuildWrapper.Environment
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCreates a newSimpleBuildWrapper.Context
for use with this wrapper.createLoggerDecorator
(Run<?, ?> build) Allows this wrapper to decorate log output.decorateLauncher
(AbstractBuild build, Launcher launcher, BuildListener listener) May be overridden but this will only take effect when used as aBuildWrapper
on anAbstractProject
.final OutputStream
decorateLogger
(AbstractBuild build, OutputStream logger) Provides an opportunity for aBuildWrapper
to decorate theBuildListener
logger to be used by the build.final Collection<? extends Action>
Action
s to be displayed in the job page.void
makeBuildVariables
(AbstractBuild build, Map<String, String> variables) May be overridden but this will only take effect when used as aBuildWrapper
on anAbstractProject
.void
makeSensitiveBuildVariables
(AbstractBuild build, Set<String> sensitiveVariables) May be overridden but this will only take effect when used as aBuildWrapper
on anAbstractProject
.final void
preCheckout
(AbstractBuild build, Launcher launcher, BuildListener listener) Provides an opportunity for aBuildWrapper
to perform some actions before SCM checkout.boolean
Determines whether or not this wrapper requires a workspace context (working directory and launcher).protected boolean
By default, when run as part of anAbstractBuild
, will run late, in thesetUp(AbstractBuild, Launcher, BuildListener)
phase.final BuildWrapper.Environment
setUp
(AbstractBuild build, Launcher launcher, BuildListener listener) Runs before theBuilder
runs (but after the checkout has occurred), and performs a set up.void
setUp
(SimpleBuildWrapper.Context context, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) Called when a segment of a build is started that is to be enhanced with this wrapper.void
setUp
(SimpleBuildWrapper.Context context, Run<?, ?> build, TaskListener listener, EnvVars initialEnvironment) Called when a segment of a build is started that is to be enhanced with this wrapper.Methods inherited from class hudson.tasks.BuildWrapper
all, getProjectAction, setUp
Methods inherited from class hudson.model.AbstractDescribableImpl
getDescriptor
-
Constructor Details
-
SimpleBuildWrapper
public SimpleBuildWrapper()
-
-
Method Details
-
requiresWorkspace
public boolean requiresWorkspace()Determines whether or not this wrapper requires a workspace context (working directory and launcher).When such a context is required (the default),
setUp(Context, Run, FilePath, Launcher, TaskListener, EnvVars)
applies. Otherwise,setUp(Context, Run, TaskListener, EnvVars)
applies.- Returns:
true
if this wrapper requires a workspace context;false
otherwise.- Since:
- 2.258
-
setUp
public void setUp(SimpleBuildWrapper.Context context, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) throws IOException, InterruptedExceptionCalled when a segment of a build is started that is to be enhanced with this wrapper.This method must be overridden when this wrapper requires a workspace context. If such a context is not required, it does not need to be overridden; it will then forward to
setUp(Context, Run, TaskListener, EnvVars)
.- Parameters:
context
- a way of collecting modifications to the environment for nested stepsbuild
- a build being runworkspace
- a workspace of the buildlauncher
- a way to start commandslistener
- a way to report progressinitialEnvironment
- the environment variables set at the outset- Throws:
AbstractMethodError
- if this wrapper requires a workspace context, and this method is not overriddenIOException
- if something fails;AbortException
for user errorsInterruptedException
- if setup is interrupted
-
setUp
public void setUp(SimpleBuildWrapper.Context context, Run<?, ?> build, TaskListener listener, EnvVars initialEnvironment) throws IOException, InterruptedExceptionCalled when a segment of a build is started that is to be enhanced with this wrapper.This method must be overridden when this wrapper does not require a workspace context, and will not be called when such a context is required.
- Parameters:
context
- a way of collecting modifications to the environment for nested stepsbuild
- a build being runlistener
- a way to report progressinitialEnvironment
- the environment variables set at the outset- Throws:
AbstractMethodError
- if this method is not overriddenIllegalStateException
- if this wrapper requires a workspace contextIOException
- if something fails;AbortException
for user errorsInterruptedException
- if setup is interrupted- Since:
- 2.258
-
createContext
@Restricted(org.kohsuke.accmod.restrictions.Beta.class) public SimpleBuildWrapper.Context createContext()Creates a newSimpleBuildWrapper.Context
for use with this wrapper.- Returns:
- a new
SimpleBuildWrapper.Context
instance
-
runPreCheckout
protected boolean runPreCheckout()By default, when run as part of anAbstractBuild
, will run late, in thesetUp(AbstractBuild, Launcher, BuildListener)
phase. May be overridden to return true, in which case this will run earlier, in thepreCheckout(hudson.model.AbstractBuild, hudson.Launcher, hudson.model.BuildListener)
phase. Ignored when not run as part of anAbstractBuild
. -
setUp
public final BuildWrapper.Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException Description copied from class:BuildWrapper
Runs before theBuilder
runs (but after the checkout has occurred), and performs a set up.- Overrides:
setUp
in classBuildWrapper
- Parameters:
build
- The build in progress for which anBuildWrapper.Environment
object 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.InterruptedException
-
preCheckout
public final void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException Description copied from class:BuildWrapper
Provides an opportunity for aBuildWrapper
to perform some actions before SCM checkout.This hook is called early on in the build (before
BuildWrapper.setUp(AbstractBuild, Launcher, BuildListener)
, but afterBuildWrapper.decorateLauncher(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.
- Overrides:
preCheckout
in classBuildWrapper
- Parameters:
build
- The build in progress for which thisBuildWrapper
is called. Never null.launcher
- The launcher. Never null.listener
- Connected to the build output. Never null. Can be used for error reporting.- Throws:
IOException
InterruptedException
-
createLoggerDecorator
Allows this wrapper to decorate log output.- Parameters:
build
- as is passed tosetUp(Context, Run, FilePath, Launcher, TaskListener, EnvVars)
- Returns:
- a filter which ignores its
build
parameter and isSerializable
; or null (the default) - Since:
- 1.608
-
decorateLogger
public final OutputStream decorateLogger(AbstractBuild build, OutputStream logger) throws IOException, InterruptedException, Run.RunnerAbortedException Description copied from class:BuildWrapper
Provides an opportunity for aBuildWrapper
to decorate theBuildListener
logger to be used by the build.This hook is called very early on in the build (even before
BuildWrapper.setUp(AbstractBuild, Launcher, BuildListener)
is invoked.)The default implementation is no-op, which just returns the
logger
parameter as-is.(
ArgumentListBuilder.add(String, boolean)
is a simpler way to suppress a single password.)- Overrides:
decorateLogger
in classBuildWrapper
- Parameters:
build
- The build in progress for which thisBuildWrapper
is called. Never null.logger
- The default logger. Never null. This method is expected to wrap this logger. This makes sure that when multipleBuildWrapper
s 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.IOException
InterruptedException
- See Also:
-
decorateLauncher
public Launcher decorateLauncher(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException, Run.RunnerAbortedException May be overridden but this will only take effect when used as aBuildWrapper
on anAbstractProject
.Provides an opportunity for a
BuildWrapper
to decorate aLauncher
to be used in the build.This hook is called very early on in the build (even before
BuildWrapper.setUp(AbstractBuild, Launcher, BuildListener)
is invoked.) The typical use ofLauncher
decoration 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
launcher
parameter as-is.- Overrides:
decorateLauncher
in classBuildWrapper
- Parameters:
build
- The build in progress for which thisBuildWrapper
is called. Never null.launcher
- The default launcher. Never null. This method is expected to wrap this launcher. This makes sure that when multipleBuildWrapper
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 thisLauncher
and create an entirely differentLauncher
and 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.IOException
InterruptedException
- Since:
- 1.608
- See Also:
-
makeBuildVariables
May be overridden but this will only take effect when used as aBuildWrapper
on anAbstractProject
.Called to define AbstractBuild.getBuildVariables(). This provides an opportunity for a BuildWrapper to append any additional build variables defined for the current build.
- Overrides:
makeBuildVariables
in classBuildWrapper
- Parameters:
build
- The build in progress for which thisBuildWrapper
is called. Never null.variables
- Contains existing build variables. Add additional build variables that you contribute to this map.- Since:
- 1.608
-
makeSensitiveBuildVariables
May be overridden but this will only take effect when used as aBuildWrapper
on anAbstractProject
.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.
- Overrides:
makeSensitiveBuildVariables
in classBuildWrapper
- Parameters:
build
- The build in progress for which thisBuildWrapper
is called. Never null.sensitiveVariables
- Contains names of sensitive build variables. Names of sensitive variables that were added withBuildWrapper.makeBuildVariables(hudson.model.AbstractBuild, java.util.Map)
- Since:
- 1.608
-
getProjectActions
Description copied from class:BuildWrapper
Action
s to be displayed in the job page.- Overrides:
getProjectActions
in classBuildWrapper
- Parameters:
job
- This object owns theBuildWrapper
. The returned action will be added to this object.- Returns:
- an empty set; this might never be called if the step is not part of the static configuration of a project; instead, add a
SimpleBuildStep.LastBuildAction
to a build when run
-