Package hudson.model.listeners
Class RunListener<R extends Run>
java.lang.Object
hudson.model.listeners.RunListener<R>
- All Implemented Interfaces:
ExtensionPoint
- Direct Known Subclasses:
GlobalBuildDiscarderListener,PeepholePermalink.RunListenerImpl,ReverseBuildTrigger.RunListenerImpl
Receives notifications about builds.
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.
- Since:
- 1.145
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ExtensionList<RunListener> all()Returns all the registeredRunListeners.booleanAllows listeners to veto build loading.createLoadAllower(Job<?, ?> job) Allows listeners to veto build loading during startup.static voidfireCompleted(Run r, TaskListener listener) Fires theonCompleted(Run, TaskListener)event.static voidfireDeleted(Run r) Fires theonDeleted(R)event.static voidfireFinalized(Run r) Fires theonFinalized(Run)event.static voidFires theonInitialize(Run)event.static voidfireStarted(Run r, TaskListener listener) Fires theonStarted(Run, TaskListener)event.voidonCompleted(R r, TaskListener listener) Called after a build is completed.voidCalled right before a build is going to be deleted.voidonFinalized(R r) Called after a build is moved to theRun.State.COMPLETEDstate.voidonInitialize(R r) Called when a Run is entering execution.voidonStarted(R r, TaskListener listener) Called when a build is started (i.e.voidregister()Deprecated.as of 1.281 PutExtensionon your class to get it auto-registered.setUpEnvironment(AbstractBuild build, Launcher launcher, BuildListener listener) Runs before theSCM.checkout(AbstractBuild, Launcher, FilePath, BuildListener, File)runs, and performs a set up.voidReverse operation ofregister().
-
Field Details
-
targetType
-
LISTENERS
List of registered listeners.
-
-
Constructor Details
-
RunListener
-
RunListener
protected RunListener()
-
-
Method Details
-
onCompleted
Called after a build is completed.- Parameters:
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.- Throws:
RuntimeException- Any exception/error thrown from this method will be swallowed to prevent broken listeners from breaking all the builds.
-
onFinalized
Called after a build is moved to theRun.State.COMPLETEDstate.At this point, all the records related to a build is written down to the disk. As such,
TaskListeneris no longer available. This happens later thanonCompleted(Run, TaskListener).- Throws:
RuntimeException- Any exception/error thrown from this method will be swallowed to prevent broken listeners from breaking all the builds.
-
onInitialize
Called when a Run is entering execution.- Parameters:
r- The started build.- Since:
- 2.9
-
onStarted
Called when a build is started (i.e. it was in the queue, and will now start running on an executor)- Parameters:
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.- Throws:
RuntimeException- Any exception/error thrown from this method will be swallowed to prevent broken listeners from breaking all the builds.
-
setUpEnvironment
public Environment setUpEnvironment(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException, Run.RunnerAbortedException Runs before theSCM.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
JobPropertys and other configuration of the project to determine the environment to inject, which allows you to achieve the equivalent ofBuildWrapper, but without UI.- Parameters:
build- The build in progress for which anEnvironmentobject 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. 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- Since:
- 1.410
-
onDeleted
Called right before a build is going to be deleted.- Parameters:
r- The build.- Throws:
RuntimeException- Any exception/error thrown from this method will be swallowed to prevent broken listeners from breaking all the builds.
-
allowLoad
@Restricted(org.kohsuke.accmod.restrictions.Beta.class) public boolean allowLoad(@NonNull Job<?, ?> job, int buildNumber) Allows listeners to veto build loading.- Parameters:
job- the job from which a build might be loadedbuildNumber- the proposed build number- Returns:
- false to veto build loading
- See Also:
-
createLoadAllower
@Restricted(org.kohsuke.accmod.restrictions.Beta.class) public IntPredicate createLoadAllower(@NonNull Job<?, ?> job) Allows listeners to veto build loading during startup. Same behavior asallowLoad(hudson.model.Job<?, ?>, int)but permits an implementation to more efficiently respond to numerous queries about historical build numbers. -
register
Deprecated.as of 1.281 PutExtensionon your class to get it auto-registered.Registers this object as an active listener so that it can start getting callbacks invoked. -
unregister
public void unregister()Reverse operation ofregister(). -
fireCompleted
Fires theonCompleted(Run, TaskListener)event. -
fireInitialize
Fires theonInitialize(Run)event. -
fireStarted
Fires theonStarted(Run, TaskListener)event. -
fireFinalized
Fires theonFinalized(Run)event. -
fireDeleted
Fires theonDeleted(R)event. -
all
Returns all the registeredRunListeners.
-
all()for read access, and useExtensionfor registration.