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.Disposermust be safely serializable. This means it should be astaticclass if nested, and define aserialVersionUID.
- Since:
- 1.599
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic final classParameter 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 classAn optional callback to run at the end of the wrapped block.Nested classes/interfaces inherited from class hudson.tasks.BuildWrapperBuildWrapper.EnvironmentNested classes/interfaces inherited from interface hudson.ExtensionPointExtensionPoint.LegacyInstancesAreScopedToHudson
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionCreates a newSimpleBuildWrapper.Contextfor 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 aBuildWrapperon anAbstractProject.final OutputStreamdecorateLogger(AbstractBuild build, OutputStream logger) Provides an opportunity for aBuildWrapperto decorate theBuildListenerlogger to be used by the build.final Collection<? extends Action> Actions to be displayed in the job page.voidmakeBuildVariables(AbstractBuild build, Map<String, String> variables) May be overridden but this will only take effect when used as aBuildWrapperon anAbstractProject.voidmakeSensitiveBuildVariables(AbstractBuild build, Set<String> sensitiveVariables) May be overridden but this will only take effect when used as aBuildWrapperon anAbstractProject.final voidpreCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) Provides an opportunity for aBuildWrapperto perform some actions before SCM checkout.booleanDetermines whether or not this wrapper requires a workspace context (working directory and launcher).protected booleanBy default, when run as part of anAbstractBuild, will run late, in thesetUp(AbstractBuild, Launcher, BuildListener)phase.final BuildWrapper.EnvironmentsetUp(AbstractBuild build, Launcher launcher, BuildListener listener) Runs before theBuilderruns (but after the checkout has occurred), and performs a set up.voidsetUp(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.voidsetUp(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.BuildWrapperall, getProjectAction, setUpMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface hudson.model.DescribablegetDescriptor
- 
Constructor Details- 
SimpleBuildWrapperpublic SimpleBuildWrapper()
 
- 
- 
Method Details- 
requiresWorkspacepublic 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:
- trueif this wrapper requires a workspace context;- falseotherwise.
- Since:
- 2.258
 
- 
setUppublic 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 steps
- build- a build being run
- workspace- a workspace of the build
- launcher- a way to start commands
- listener- a way to report progress
- initialEnvironment- the environment variables set at the outset
- Throws:
- AbstractMethodError- if this wrapper requires a workspace context, and this method is not overridden
- IOException- if something fails;- AbortExceptionfor user errors
- InterruptedException- if setup is interrupted
 
- 
setUppublic 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 steps
- build- a build being run
- listener- a way to report progress
- initialEnvironment- the environment variables set at the outset
- Throws:
- AbstractMethodError- if this method is not overridden
- IllegalStateException- if this wrapper requires a workspace context
- IOException- if something fails;- AbortExceptionfor user errors
- InterruptedException- if setup is interrupted
- Since:
- 2.258
 
- 
createContext@Restricted(org.kohsuke.accmod.restrictions.Beta.class) public SimpleBuildWrapper.Context createContext()Creates a newSimpleBuildWrapper.Contextfor use with this wrapper.- Returns:
- a new SimpleBuildWrapper.Contextinstance
 
- 
runPreCheckoutprotected 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.
- 
setUppublic final BuildWrapper.Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException Description copied from class:BuildWrapperRuns before theBuilderruns (but after the checkout has occurred), and performs a set up.- Overrides:
- setUpin class- BuildWrapper
- Parameters:
- build- The build in progress for which an- BuildWrapper.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.
- InterruptedException
 
- 
preCheckoutpublic final void preCheckout(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException Description copied from class:BuildWrapperProvides an opportunity for aBuildWrapperto 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:
- preCheckoutin class- BuildWrapper
- Parameters:
- build- The build in progress for which this- BuildWrapperis 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
 
- 
createLoggerDecoratorAllows this wrapper to decorate log output.- Parameters:
- build- as is passed to- setUp(Context, Run, FilePath, Launcher, TaskListener, EnvVars)
- Returns:
- a filter which ignores its buildparameter and isSerializable; or null (the default)
- Since:
- 1.608
 
- 
decorateLoggerpublic final OutputStream decorateLogger(AbstractBuild build, OutputStream logger) throws IOException, InterruptedException, Run.RunnerAbortedException Description copied from class:BuildWrapperProvides an opportunity for aBuildWrapperto decorate theBuildListenerlogger 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 loggerparameter as-is.( ArgumentListBuilder.add(String, boolean)is a simpler way to suppress a single password.)- Overrides:
- decorateLoggerin class- BuildWrapper
- Parameters:
- build- The build in progress for which this- BuildWrapperis called. Never null.
- logger- The default logger. Never null. This method is expected to wrap this logger. This makes sure that when multiple- BuildWrappers 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:
 
- 
decorateLauncherpublic 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 aBuildWrapperon anAbstractProject.Provides an opportunity for a BuildWrapperto decorate aLauncherto 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 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.- Overrides:
- decorateLauncherin class- BuildWrapper
- Parameters:
- build- The build in progress for which this- BuildWrapperis called. Never null.
- launcher- The default launcher. Never null. This method is expected to wrap this launcher. This makes sure that when multiple- BuildWrappers 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- Launcherand create an entirely different- Launcherand 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:
 
- 
makeBuildVariablesMay be overridden but this will only take effect when used as aBuildWrapperon 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:
- makeBuildVariablesin class- BuildWrapper
- Parameters:
- build- The build in progress for which this- BuildWrapperis called. Never null.
- variables- Contains existing build variables. Add additional build variables that you contribute to this map.
- Since:
- 1.608
 
- 
makeSensitiveBuildVariablesMay be overridden but this will only take effect when used as aBuildWrapperon 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:
- makeSensitiveBuildVariablesin class- BuildWrapper
- Parameters:
- build- The build in progress for which this- BuildWrapperis 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)
- Since:
- 1.608
 
- 
getProjectActionsDescription copied from class:BuildWrapperActions to be displayed in the job page.- Overrides:
- getProjectActionsin class- BuildWrapper
- Parameters:
- job- This object owns the- BuildWrapper. 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.LastBuildActionto a build when run
 
 
-