public abstract class RunListener<R extends Run> extends Object implements ExtensionPoint
Listener is always Hudson-wide, so once registered it gets notifications for every build that happens in this Hudson.
This is an abstract class so that methods added in the future won't break existing listeners.
ExtensionPoint.LegacyInstancesAreScopedToHudson
Modifier and Type | Field and Description |
---|---|
static CopyOnWriteList<RunListener> |
LISTENERS
|
Class<R> |
targetType |
Modifier | Constructor and Description |
---|---|
protected |
RunListener() |
protected |
RunListener(Class<R> targetType) |
Modifier and Type | Method and Description |
---|---|
static ExtensionList<RunListener> |
all()
Returns all the registered
RunListener s. |
static void |
fireCompleted(Run r,
TaskListener listener)
Fires the
onCompleted(Run, TaskListener) event. |
static void |
fireDeleted(Run r)
Fires the
onDeleted(R) event. |
static void |
fireFinalized(Run r)
Fires the
onFinalized(Run) event. |
static void |
fireInitialize(Run r)
Fires the
onInitialize(Run) event. |
static void |
fireStarted(Run r,
TaskListener listener)
Fires the
onStarted(Run, TaskListener) event. |
void |
onCompleted(R r,
TaskListener listener)
Called after a build is completed.
|
void |
onDeleted(R r)
Called right before a build is going to be deleted.
|
void |
onFinalized(R r)
Called after a build is moved to the
Run.State.COMPLETED state. |
void |
onInitialize(R r)
Called when a Run is entering execution.
|
void |
onStarted(R r,
TaskListener listener)
Called when a build is started (i.e.
|
void |
register()
Deprecated.
as of 1.281
Put
Extension on your class to get it auto-registered. |
Environment |
setUpEnvironment(AbstractBuild build,
Launcher launcher,
BuildListener listener)
Runs before the
SCM.checkout(AbstractBuild, Launcher, FilePath, BuildListener, File) runs, and performs a set up. |
void |
unregister()
Reverse operation of
register() . |
@Deprecated public static final CopyOnWriteList<RunListener> LISTENERS
public void onCompleted(R r, @NonNull TaskListener listener)
r
- The completed build.listener
- The listener for this build. This can be used to produce log messages, for example,
which becomes a part of the "console output" of this build. But when this method runs,
the build is considered completed, so its status cannot be changed anymore.RuntimeException
- Any exception/error thrown from this method will be swallowed to prevent broken listeners
from breaking all the builds.public void onFinalized(R r)
Run.State.COMPLETED
state.
At this point, all the records related to a build is written down to the disk. As such,
TaskListener
is no longer available. This happens later than onCompleted(Run, TaskListener)
.
RuntimeException
- Any exception/error thrown from this method will be swallowed to prevent broken listeners
from breaking all the builds.public void onInitialize(R r)
r
- The started build.public void onStarted(R r, TaskListener listener)
r
- The started build.listener
- The listener for this build. This can be used to produce log messages, for example,
which becomes a part of the "console output" of this build.RuntimeException
- Any exception/error thrown from this method will be swallowed to prevent broken listeners
from breaking all the builds.public Environment setUpEnvironment(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException, Run.RunnerAbortedException
SCM.checkout(AbstractBuild, Launcher, FilePath, BuildListener, File)
runs, and performs a set up.
Can contribute additional properties/env vars to the environment.
A typical strategy is for implementations to check JobProperty
s and other configuration
of the project to determine the environment to inject, which allows you to achieve the equivalent of
BuildWrapper
, but without UI.
build
- The build in progress for which an 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.Run.RunnerAbortedException
- If a fatal error is detected and the callee handled it gracefully, throw this exception
to suppress a stack trace by the receiver.InterruptedException
public void onDeleted(R r)
r
- The build.RuntimeException
- Any exception/error thrown from this method will be swallowed to prevent broken listeners
from breaking all the builds.@Deprecated public void register()
Extension
on your class to get it auto-registered.public void unregister()
register()
.public static void fireCompleted(Run r, @NonNull TaskListener listener)
onCompleted(Run, TaskListener)
event.public static void fireInitialize(Run r)
onInitialize(Run)
event.public static void fireStarted(Run r, TaskListener listener)
onStarted(Run, TaskListener)
event.public static void fireFinalized(Run r)
onFinalized(Run)
event.public static void fireDeleted(Run r)
onDeleted(R)
event.public static ExtensionList<RunListener> all()
RunListener
s.Copyright © 2004–2022. All rights reserved.