public abstract class SimpleBuildWrapper extends 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:
AbstractBuild.getWorkspace()
with the provided path.
AbstractBuild.getProject()
with Run.getParent()
.
FilePath.toComputer()
rather than Computer.currentComputer()
.
AbstractBuild.getBuildVariables()
if you are not passed an AbstractBuild
(treat it like an empty map).
SimpleBuildWrapper.Disposer
must be safely serializable. This means it should be a static
class if nested, and define a serialVersionUID
.
Modifier and Type | Class and Description |
---|---|
static class |
SimpleBuildWrapper.Context
Parameter passed to
setUp(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 |
SimpleBuildWrapper.Disposer
An optional callback to run at the end of the wrapped block.
|
BuildWrapper.Environment
ExtensionPoint.LegacyInstancesAreScopedToHudson
Constructor and Description |
---|
SimpleBuildWrapper() |
Modifier and Type | Method and Description |
---|---|
ConsoleLogFilter |
createLoggerDecorator(Run<?,?> build)
Allows this wrapper to decorate log output.
|
Launcher |
decorateLauncher(AbstractBuild build,
Launcher launcher,
BuildListener listener)
May be overridden but this will only take effect when used as a
BuildWrapper on an AbstractProject . |
OutputStream |
decorateLogger(AbstractBuild build,
OutputStream logger)
Provides an opportunity for a
BuildWrapper to decorate the BuildListener logger to be used by the build. |
Collection<? extends Action> |
getProjectActions(AbstractProject job)
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 a
BuildWrapper on an AbstractProject . |
void |
makeSensitiveBuildVariables(AbstractBuild build,
Set<String> sensitiveVariables)
May be overridden but this will only take effect when used as a
BuildWrapper on an AbstractProject . |
void |
preCheckout(AbstractBuild build,
Launcher launcher,
BuildListener listener)
Provides an opportunity for a
BuildWrapper to perform some actions before SCM checkout. |
protected boolean |
runPreCheckout()
By default, when run as part of an
AbstractBuild , will run late, in the setUp(AbstractBuild, Launcher, BuildListener) phase. |
BuildWrapper.Environment |
setUp(AbstractBuild build,
Launcher launcher,
BuildListener listener)
Runs before the
Builder runs (but after the checkout has occurred), and performs a set up. |
abstract 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.
|
all, getProjectAction, setUp
getDescriptor
public abstract void setUp(SimpleBuildWrapper.Context context, Run<?,?> build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) throws IOException, InterruptedException
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 outsetIOException
- if something fails; AbortException
for user errorsInterruptedException
- if setup is interruptedprotected boolean runPreCheckout()
AbstractBuild
, will run late, in the setUp(AbstractBuild, Launcher, BuildListener)
phase.
May be overridden to return true, in which case this will run earlier, in the preCheckout(hudson.model.AbstractBuild, hudson.Launcher, hudson.model.BuildListener)
phase.
Ignored when not run as part of an AbstractBuild
.public final BuildWrapper.Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException
BuildWrapper
Builder
runs (but after the checkout has occurred), and performs a set up.setUp
in class BuildWrapper
build
- The build in progress for which an BuildWrapper.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.IOException
- terminates the build abnormally. Hudson will handle the exception
and reports a nice error message.InterruptedException
public final void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException
BuildWrapper
BuildWrapper
to perform some actions before SCM checkout.
This hook is called early on in the build (before BuildWrapper.setUp(AbstractBuild, Launcher, BuildListener)
,
but after BuildWrapper.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.
preCheckout
in class BuildWrapper
build
- The build in progress for which this BuildWrapper
is called. Never null.launcher
- The launcher. Never null.listener
- Connected to the build output. Never null. Can be used for error reporting.IOException
InterruptedException
@CheckForNull public ConsoleLogFilter createLoggerDecorator(@Nonnull Run<?,?> build)
build
- as is passed to setUp(Context, Run, FilePath, Launcher, TaskListener, EnvVars)
build
parameter and is Serializable
; or null (the default)public final OutputStream decorateLogger(AbstractBuild build, OutputStream logger) throws IOException, InterruptedException, Run.RunnerAbortedException
BuildWrapper
BuildWrapper
to decorate the BuildListener
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.)
decorateLogger
in class BuildWrapper
build
- The build in progress for which this BuildWrapper
is called. Never null.logger
- The default logger. Never null. This method is expected to wrap this logger.
This makes sure that when multiple BuildWrapper
s attempt to decorate the same logger
it will sort of work.Run.RunnerAbortedException
- If a fatal error is detected but the implementation handled it gracefully, throw this exception
to suppress stack trace.IOException
InterruptedException
ConsoleLogFilter
public Launcher decorateLauncher(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException, Run.RunnerAbortedException
BuildWrapper
on an AbstractProject
.
Provides an opportunity for a BuildWrapper
to decorate a Launcher
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 of Launcher
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.
decorateLauncher
in class BuildWrapper
build
- The build in progress for which this BuildWrapper
is called. Never null.launcher
- The default launcher. Never null. This method is expected to wrap this launcher.
This makes sure that when multiple 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 Launcher
and create an entirely different Launcher
and return it, too.listener
- Connected to the build output. Never null. Can be used for error reporting.Run.RunnerAbortedException
- If a fatal error is detected but the implementation handled it gracefully, throw this exception
to suppress stack trace.IOException
InterruptedException
LauncherDecorator
public void makeBuildVariables(AbstractBuild build, Map<String,String> variables)
BuildWrapper
on an AbstractProject
.
Called to define AbstractBuild.getBuildVariables(). This provides an opportunity for a BuildWrapper to append any additional build variables defined for the current build.
makeBuildVariables
in class BuildWrapper
build
- The build in progress for which this BuildWrapper
is called. Never null.variables
- Contains existing build variables. Add additional build variables that you contribute
to this map.public void makeSensitiveBuildVariables(AbstractBuild build, Set<String> sensitiveVariables)
BuildWrapper
on an AbstractProject
.
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.
makeSensitiveBuildVariables
in class BuildWrapper
build
- The build in progress for which this BuildWrapper
is called. Never null.sensitiveVariables
- Contains names of sensitive build variables. Names of sensitive variables
that were added with BuildWrapper.makeBuildVariables(hudson.model.AbstractBuild, java.util.Map)
public final Collection<? extends Action> getProjectActions(AbstractProject job)
Action
s to be displayed in the job page.getProjectActions
in class BuildWrapper
job
- This object owns the BuildWrapper
. The returned action will be added to this object.SimpleBuildStep.LastBuildAction
to a build when runCopyright © 2004–2019. All rights reserved.